Page 1 of 1

Problems with the PHP session

Posted: Mon Sep 17, 2007 7:05 am
by fastfingertips

Code: Select all

<?php

session_start();
$_SESSION['joy'] = 'happy';

$joy = 'joy joy';

echo $_SESSION['joy'];

?>
With the register globals turned on, when i run this script first time i got "happy" at the second echo, but when i make refresh and any refresh after that i get "joy joy", can you explain me why this happens? It seems like writing the new value in the session file is delayed and i don't understand why.

Posted: Mon Sep 17, 2007 7:16 am
by Begby
I am not sure why this is happening but it appears to be yet another of the many reasons to always disable register globals.

Re: Problems with the PHP session

Posted: Mon Sep 17, 2007 7:28 am
by superdezign
fastfingertips wrote:With the register globals turned on, when i run this script first time i got "happy" at the second echo, but when i make refresh and any refresh after that i get "joy joy", can you explain me why this happens? It seems like writing the new value in the session file is delayed and i don't understand why.
register_globals does not make $_SESSION['joy'] and $joy point to the same memory address. register_globals actually copies the values from the superglobal arrays into variables. So, when you change $joy, the actual $_SESSION['joy'] is not altered, but the final session data is.