note 14238 added to language.variables.scope.php

From: Date: Mon, 23 Jul 2001 18:14:39 +0000
Subject: note 14238 added to language.variables.scope.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15716@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; ?> http://www.php.net/manual/en/language.variables.scope.php

« previous php.notes (#15716) next »