Re: accessing session variables in functions
| From: | Michael Kimsal | Date: | Fri, 20 Oct 2000 20:27:26 +0000 |
| Subject: | Re: accessing session variables in functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21472@lists.php.net to get a copy of this message | ||
session_start();
session_register("count");
function go()
{
global $count;
$count++;
print "visited " . $count . " times";
}
Try that.
We had problems with this, and IRC discussions and I think even a private email
or two with someone from the list indicated that the above was the correct
method,
and obviously no one at our company understood variable scope. Personally, I
think
it had nothing to do with variable scope so much as function scope - I start a
session
in a function, that session info should be available to that function's code.
But hey,
what do I know? ;)
D Robinson wrote:
> Since no-one answered my last email (no hard feelings:)), just maybe,
> someone could help me with this:
>
> Niether:
>
> function go()
> {
> session_start();
> session_register("count");
> $HTTP_SESSION_VARS["count"]++;
> print "visited " . $HTTP_SESSION_VARS["count"] . "
> times";
> }
>
> NOR:
>
> function go()
> {
> global $count;
> session_start();
> session_register("count");
> $count++;
> print "visited " . $count . " times";
> }
>
> will make the $count rise when reaccessing the page, but they both work fine
> when when not in a function
>
> Regards
>
> Dale Robinson
>
--
==========================
Michael Kimsal
http://www.tapinternet.com
734-480-9961