Re: Confused object in session variable.
| From: | John Gunther | Date: | Tue, 06 Nov 2001 15:08:51 +0000 |
| Subject: | Re: Confused object in session variable. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73610@lists.php.net to get a copy of this message | ||
2 instances of $HTTP_SESSION_VARS :
I see no one replied, but I have a similar problem that is puzzling the hell out of me, too. It appears there are 2 instances of HTTP_SESSION_VARS, one in the main program and one in the function, even though I have a "global $HTTP_SESSION_VARS;" statement in the function. What's puzzling is that both maintain their values independently, i.e. if I run the page 3 times, the main program session values and those in the function each preserve their version of the session variable values. We really need this explained, as "register_globals on" complicates security issues. To me, this seems likely to be a PHP bug.
Can anyone explain what's going on?
John Gunther
Steve Cayford wrote:
An update... I had register_globals turned off. Now that I've turned register_globals on and changed my references from $HTTP_SESSION_VARS['ucAuthoUser'] to $ucAuthoUser it works as I expect. I'm not real happy with having register_globals on, though, and I'd like to figure out what I was doing wrong. Thanks for any suggestions. -Steve On Thursday, October 25, 2001, at 12:07 PM, Steve Cayford wrote:Well, it's probably me that's confused. I have an authenticate() function which should start a session and if the user is not logged in then show the login screen otherwise return after storing and registering a user object in a session variable. This object has accessor methods to get the login name, access level, etc... This seems to work okay--within the authenticate function I can access the object in the HTTP_SESSION_VARS array. But as soon as I return to the main script it's gone. I must be doing something wrong with the scoping, but I can't see what. Any thoughts? Here's the code: <?php /* --------- */ /* index.php */ /* --------- */ require_once('ucautho/ucautho.inc'); authenticate(); print("From index testUser: " . $testUser->getLogin() . "<br>\n"); print("From index HTTP_SESSION_VARS['ucAuthoUser']: "); print($HTTP_SESSION_VARS['ucAuthoUser']->getLogin() . "<br>\n"); //this is line 12 ?> <?php /* ------------------- */ /* ucautho/ucautho.inc */ /* ------------------- */ function authenticate($appName="") {global $HTTP_SESSION_VARS, $HTTP_POST_VARS; global $testUser; session_name("UCAutho"); session_start();if (isset($HTTP_SESSION_VARS['ucAuthoUser']) && $HTTP_SESSION_VARS['ucAuthoUser']->isValid()) { return; } else { if (isset($HTTP_POST_VARS['authoSubmit'])) { $HTTP_SESSION_VARS['ucAuthoUser'] =& new UcAuthoUser($HTTP_POST_VARS['authoLogin'],$HTTP_POST_VARS['authoPword']); if ($HTTP_SESSION_VARS['ucAuthoUser']->isValid()) { session_register('ucAuthoUser'); $testUser = $HTTP_SESSION_VARS['ucAuthoUser']; print("From authenticate testUser: " . $testUser->getLogin() . "<br>\n"); print("From authenticate HTTP_SESSION_VARS['ucAuthoUser']: "); print($HTTP_SESSION_VARS['ucAuthoUser']->getLogin() . "<br>\n"); return; } } showLogin($appName); }} /* more functions and the class declaration snipped */ ?> Here's what I get when I login as 'steve' with a good password: From authenticate testUser: steve From authenticate HTTP_SESSION_VARS['ucAuthoUser']: steve From index testUser: steve From index HTTP_SESSION_VARS['ucAuthoUser']: Fatal error: Call to a member function on a non-object in /home/httpd/html/ucdamage/index.php on line 12 Note the testUser works in both instances, the session var only works inside the function. -Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net