note 14238 deleted from language.variables.scope by jimw

From: Date: Sat, 08 Dec 2001 21:43:37 +0000
Subject: note 14238 deleted from language.variables.scope by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22221@lists.php.net to get a copy of this message
Why re-registering session variables with post and get doesn't work after the first time. (an explanation) If you post a variable "test" with a value of "one" to a file that looks like this: <?php session_register("test"); echo $test; ?> It will successfully register $test as "one", however, if you repost the form with "test"="two", it will not update the value of the session variable. Because session variables can be accessed like local variables, attempting to re-register a session variable in this manner will only cause the variable to be re-written with it's own value. Consider the following: <?php session_register("test"); $GLOBALS["test"] = $test; echo $test; ?> This is essentially what is happening, to fix this, change it to the following: <?php session_register("test"); $GLOBALS["test"] = $HTTP_POST_VARS["test"]; echo $test; ?>

« previous php.notes (#22221) next »