PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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?
<?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.';
}
?>