note 45534 deleted from ref.session by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 18:38:39 +0000 |
| Subject: | note 45534 deleted from ref.session by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142243@lists.php.net to get a copy of this message | ||
Note Submitter: cryogen AT mac dot com
----
Although this IS mentioned in the PHP manual, it is not very clear and can lead to some very hard to
track down bugs.
When REGISTER_GLOBALS is ON on a server, local variables of the same name as a session variable can
leak their values into the session during a POST or GET.
For example, if you run script "SESS_TEST1.PHP" below, the local var $animal will bleed
its value of "I am an Elephant" into the session variable $_SESSION['animal'],
which should have a value of "I am a Monkey". Beware!
<?php
// SESS_TEST1.PHP
session_start();
$_SESSION['animal'] = 'I am a Monkey';
$animal = 'I am an Elephant';
$value = 249;
echo "<script>window.location=\"sess_test2.php".
"?animal=$animal&value=$value\"</script>";
?>
<?php
// SESS_TEST2.PHP
session_start();
$animal = $_REQUEST['animal'];
$value = $_REQUEST['value'];
echo "SESSION['animal'] = ".$_SESSION['animal']." (should say
\"I am a Monkey\")<br/>";
echo "\$animal = ".$animal."<br/>";
echo "\$value = ".$value."<br/>";
?>