[SOLVED] $_Session takes on unexpected value. Bug?
Posted: Sat Jul 10, 2004 8:03 am
Run the following code and see (and please explain to me why this should happen) that $_SESSION['froop'] mysteriously takes on the value of a variable. What is going on here?
feyd | Please use
Code: Select all
<?php
session_start();
echo phpversion();
echo '<pre>$_SESSION (0): ';
print_r($_SESSION);
echo '</pre>';
$_SESSION['froop']=0;
$froop='strawberry';
// The second time around we see that mysteriously $_SESSION['froop'] has
// taken on the value 'strawberry'. Watch the birdie...
echo '<pre>$_SESSION (1): ';
print_r($_SESSION);
echo '</pre>';
// The following condition should NEVER be true as $_SESSION['froop']
// is never explicitly set to anything but 0. However...
if(strcmp($_SESSION['froop'],'strawberry')==0)
{
echo '<pre>$_SESSION (2): ';
print_r($_SESSION);
echo '</pre>';
unset($_SESSION);
session_destroy();
echo '<p>Session gone.';
}
else
{
echo 'This was the first run. Now do Refresh and see.';
}
?>feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]