Re: global sessions
| From: | Plutarck | Date: | Wed, 18 Apr 2001 13:40:45 +0000 |
| Subject: | Re: global sessions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49209@lists.php.net to get a copy of this message | ||
If you want to access a global variable in a function, it must be declared
"GLOBAL". Otherwise PHP's local scope would be totally useless.
If you want to access a variable inside of a function, you must explicitly
declare it as global.
There are a few exceptions such as $GLOBALS, but they should not be relied
on.
If nothing else, not using global in a function that requires a variable
that is declared outside of that function is bad practice.
Note: Try using get_defined_variables() inside of a function and see what it
returns.
--
Plutarck
Should be working on something...
...but forgot what it was.
""Ben"" <ben@nyip.net> wrote in message
news:9bjvo1$irv$1@toye.p.sourceforge.net...
> i'm trying to use sessions with my project, but it seems that registered
> variables in a session aren't global by default.
> It doesn't even seem like the session is global, because if I reference
the
> sessionid (which only shows up if cookies are disabled)
> by using <?=SID?>, it shows up within a function, if I reference it
from
> within the function.
>
> if anyone can help me make my variables (such as $user, and $active)
> globally registered with the session, I would be very grateful.
> maybe its the cookie not being global, that would explain why the
sessionid
> shows up only from within a function (but not in the global scope)
>
> so...i guess my question is how can i globalize a session?
>
> thanks
> ben
> ben@nyip.net
>
>
>
>
>
> --
> 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
>