Solved

Php / phplib error

Posted on 2000-02-14
17
354 Views
Last Modified: 2008-03-17
have a problem with php/phplib. Every now and again i get

Warning: $user is not an object in page.inc on line 68

Fatal error: Member function used on a non-object in page.inc on line 68

On my pages. I am NOT using a variable named $user. I am doing a page_open and page_close on all pages (the error occurs in the page_close). Sometimes you can loose the error by closing all browser windows and restarting. Sometimes it shows on all pages, sometimes just on a few, or one. And most of the time it works just dandy.

If you would like to see my exact server config etc (aswell as some code snippet) please refer to the link below.

http://horde.tdyc.com/imp-0002/msg00283.html


Regards Jan.
0
Comment
Question by:j2
  • 8
  • 6
  • 3
17 Comments
 
LVL 2

Expert Comment

by:maxkir
ID: 2519534
Try to insert debug code like echo $user before page_close() call. And add global $sess, $user in your functions:

<?php
function session_header($title) {
 global $sess, $user;
 page_open(array("sess" => "CS_Session", "user" => "CS_User"));
 echo "<html><head><title>\n";
 echo "$title\n";
 echo "</title>\n";
 echo "</head>\n";
 echo "<body bgcolor=\"#B07879\" background=\"http://localhost/images/cs-logo-fill2.jpg\" topmargin=\"0\" leftmargin=\"0\" style=\"font-family: Arial, sans-serif\" >\n";
  }
 

function session_footer() {
    global $sess, $user;
    echo '</body></html>';
    print $user;
    page_close();
  }
?>
0
 
LVL 12

Author Comment

by:j2
ID: 2519996
since footer is always called after header, do i need global directive in footer?
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2521885
AFAIK, 'global' definition is local to the function it is used in. So you have always use global in functions/object methods. Another way to access globals variables - use $GLOBALS array.
0
 
LVL 1

Expert Comment

by:aikon
ID: 2521889
Hi j2,

If you only want use phplibs to manage sessions variables you don't need use
"user" => "CS_User" parameter.

My code looks like:
<?php
// $theVar is a session variable. It was registered with REGISTER function
// $theNewVar is a new session variable I'm going to register it
// mySessClass is my custom session class in local.inc file

 php_open(array("session"=>"mySessClass"));

 echo "TheVar= $theVar";
 $theNewVar = $theVar + 10;
 $mySessClass->register("theNewVar");

 php_close();
?>
0
 
LVL 12

Author Comment

by:j2
ID: 2521902
I think i wrote in the link i provided that i only added that since it was suggested by someone else, it makes no difference to my problem.

maxkir i dont think the global is the answer, since the use of global is not suggested anywhere in the phplib docs :-/
0
 
LVL 1

Accepted Solution

by:
aikon earned 100 total points
ID: 2522052
J2,

Be carefull with the PHP functions variables scope.

I have a look at your code, and I suggest you to don't open/close a session into a function because it could be only available into the function body.

Try this one:
<?php
 page_open(array("sess" => "CS_Session"));

 function session_header($title) {
  echo "<html><head><title>\n";
  echo "$title\n";
  echo "</title>\n";
  echo "</head>\n";
  echo "<body bgcolor=\"#B07879\" background=\"http://localhost/images/cs-logo-fill2.jpg\" topmargin=\"0\" leftmargin=\"0\" style=\"font-family: Arial, sans-serif\" >\n";
 }
 

 function session_footer() {
    echo '</body></html>';
 }

 page_close();
?>

Regards
0
 
LVL 12

Author Comment

by:j2
ID: 2522087
Will try wednesday / thursday.

Out of curiosity, what is the _real_ difference between your code and mine?

I think i am out of my league here :=)
0
 
LVL 1

Expert Comment

by:aikon
ID: 2522103
I put the php_open() and php_close()  outside of your functions.

Regards :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:maxkir
ID: 2522154
Well, 'global' is not mentioned, but it is supposed to be used when you put your page_open/close code in functions - so, as aikon mentioned, you've changed variables scope.

Try adding 'global' just to make sure that I'm wrong ;-))). If you remove
"user"=>CS_User, it could bi simple
global $sess; in your  functions.

Good luck,
0
 
LVL 12

Author Comment

by:j2
ID: 2522313
Ah, now i see, rewriting the common inc in that fashion would make sure that each file that includes that file will get a page open and close.. I see. Now, if i would like to use another session setting i would just have to moce it to another common inc (or whatever filename) right?

This might very well work, but as i said, i wont have time to experiment until thursday prolly.

But i think i have seen the light :)
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2522575
Just including common.inc will not do the trick.
When you make page_open, you read values of stored variables from DB,
when you do page_close, you save this values back to the DB. So you vave to call page_close  *after* changing of variables you want to store.
Code like this:

include("common.inc");
$var_to_store = "value";

will not work if you will not call page_close()  at the end.
So, common.inc shouldn't contain page_close() call.

You can do two ways (using code above):
<?php
include("common.inc");
$sess->register("var_to_store");
$var_to_store = "value";
session_footer();
page_close();
?>

OR ( if you leave page_close() in session_footer() )

<?php
include("common.inc");
$sess->register("var_to_store");
$var_to_store = "value";
session_footer();
?>

I'd do it this way:
<?php
include("common.inc");
session_header();
$sess->register("var_to_store");
$var_to_store = "value";
session_footer();
?>

0
 
LVL 12

Author Comment

by:j2
ID: 2524515
Gah, how shall i call this?

Aikon mentioned the scope of variables first (which was the problem).. but maxkir aswell gave valuable input.

But since i cant split the points, the winner must be aikon.

Hey maxkir, posting another question in a sec should be easy, but it got me scratching my head :=)
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2524589
I suggest that 'global' statement resolves variable scope problem ;-)))
Anyway, most important thing that you've got a solution.
0
 
LVL 12

Author Comment

by:j2
ID: 2524613
Dang.. you're right.. yo uknow what, ill see if customer service can transfer some points to you. :)
0
 
LVL 12

Author Comment

by:j2
ID: 2524829
Gah.. the error just returned :(
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2526039
In what configuration ?
0
 
LVL 12

Author Comment

by:j2
ID: 2526069
IE5.01sp1 which is probably the culprit, with the cache bug. After the redefinition of my functions the problem seems to have dissapeared for other browsers tho.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CA single sign on 2 74
Sql query on a varchar that is numeric. 8 26
What is the best PDF generator to use? 1 28
Configuring a checkbox in CSS and php 18 31
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now