RE: [PHP] Session Variables
| From: | Johnson, Kirk | Date: | Thu, 03 May 2001 20:46:07 +0000 |
| Subject: | RE: [PHP] Session Variables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-51332@lists.php.net to get a copy of this message | ||
The session variable values get stored to the session file (or database, or
wherever your configuration is set to store them) at the end of script 1.
When session_start() is called in script 2, those values get restored from
the session file. So, your results are expected: PHP needs to store the
session values from script 1 before they can be retrieved by script 2.
Kirk
> -----Original Message-----
> From: Nikhil Goyal [mailto:ngoyal@nypirg.org]
> Sent: Thursday, May 03, 2001 2:41 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Session Variables
>
>
> Funnily - doesn't work for me. Here's what I got:
>
> Script #1
> #!/usr/local/bin/php
> <?php
> session_start();
> if (!isset($count)) { echo "Setting count";
> session_register("count"); }
> else echo $count;
> $count++;
> sleep(60);
> ?>
>
> Script #2
> #!/usr/local/bin/php
> <?php
> session_start();
> echo $count;
> ?>
>
> If I start script#1 (and it sleep()s), wait 10 seconds, then
> launch script
> #2 in a separate browser window, script #2 returns empty.
> However once the
> sleep() is completed and I refresh the window with script #2,
> the output is
> okay (1).
>
> Why does this happen?
>
> Nikhil
>
> ""Johnson, Kirk"" <kjohnson@zootweb.com> wrote in message
> news:01A4B59FD1EBD311838100A0C98BE0D9AD5939@chef.zootweb.com...
> > > -----Original Message-----
> > > From: Nikhil Goyal [mailto:ngoyal@nypirg.org]
> >
> > > When does a session variable become available?
> Immediately after the
> > > session_register command or after the script ends?
> >
> > Immediately after it is assigned.
> >
> > > And if the commands are as follows:
> > >
> > > session_start();
> > > session_register("hello");
> > > $hello=3;
> > >
> > > will the session variable $hello be set to 3 or do I have to
> > > add another
> > > session_register() call after changing the value?
> >
> > No additional calls are needed. You will need to do
> session_start() on the
> > next page if you want to access $hello there.
> >
> > Kirk