Re: Session Variables in a Class
| From: | micro brew | Date: | Wed, 10 Sep 2003 07:05:24 +0000 |
| Subject: | Re: Session Variables in a Class | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-162146@lists.php.net to get a copy of this message | ||
Thanks Curt,
You were absolutely correct. Removing the
session_register() lines before the $_SESSION[] fixed
the problem. By mixing the two before, it actually
would register the variable so I could later test for
the registered session variable but it did not retain
the value I assigned it. Thanks again for the help.
Mike
>* Thus wrote micro brew (microbrewclub@yahoo.com):
>> Hi everyone,
>>
>> I've been experimenting with sessions. I can make
>> them work just fine in a normal PHP page. But when
I
>> create a class and try to define a session variable
>> within a method in the class it won't work. I've
>> tried setting the session variable directly
>> ($_SESSION['name']='somevalue') but that didn't
work.
>> The normal way of setting it -
>> session_start();
>> session_register('name');
>> $name='somevalue';
>
>You might want to read
> http://php.net/session
>
>You are most likley running into a register_globals
>issue.
>
>A couple things to note:
>
> . You must not mix $_SESSION[] access with
>session_register()
> anywhere in your script.
>
> . When you issue session_register('name') inside
>your class it is
> declaring the global var $name as a session var,
not >the $name in
> your script.
>
>
>
>Curt
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com