Problems with the PHP session

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!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Problems with the PHP session

Post 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.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Problems with the PHP session

Post 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.
Post Reply