Re: [PHP4BETA] Bug with session

[email protected] (Steve Langasek)
Newsgroups php.version4
Message-ID <[email protected]>
On Mon, 22 May 2000, Vadim Tkachenko wrote:

> 1.phtml
> <?
> session_start();
> session_register("vara");
> session_register("varb");

> $vara="Value A";
> $varb="Value B";

> echo "Goto <A href='2.phtml?".SID."'>page 2</a>";
> ?>

> 2.phtml
> <?
> $varb="No Value";

> session_start();
> session_register("vara");

> echo "vara=".$vara."<BR>";
> echo "varb=".$varb."<BR>";

> ?>

> When I run page 1.phtml, then goto 2.phtml - in result I get:
> vara=Value A
> varb=Value B

> This is bug! 
> $varb must be "No value".

Why is this a bug?

In 1.phtml, you've started a session, and registered the two variables $vara
and $varb as session data.

In 2.phtml, you've set $varb to "No Value", and *then* you've restored all of
the session data by calling session_start().  This overwrites $varb with the
previous saved value.  The following session_register() call is a no-op,
because vara is already a registered variable with the session.

AFAICT, this is all per the documentation in the PHP manual.

HTH,
Steve Langasek
postmodern programmer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.