Page 1 of 1

Relationship netween $_SESSION and local variables

Posted: Wed Nov 27, 2002 11:47 pm
by Bill H
Can someone explain why this happens:

Code: Select all

<?php
    print_r($_SESSION);              // $_SESSIONї'Assn'] = "none" at this point
    $Assn = $_POSTї'Number'];
    print_r($_SESSION);              // $_SESSIONї'Assn'] = "1150" at this point
?>

Posted: Thu Nov 28, 2002 12:15 am
by mydimension
it looks like register_globals is turned on. can you check? that is a weird happening.

Posted: Thu Nov 28, 2002 2:48 am
by twigletmac
Have you registered $Assn as a session variable (and as mydimension pointed out got registered_globals on):

Code: Select all

session_register('Assn');
Code like the above and reg_globals on could cause this.

Mac

Posted: Thu Nov 28, 2002 6:42 am
by Bill H
Yes, register globals is turned on, but

No, I have not done "session_register('Assn');" anywhere in any file.

Posted: Thu Nov 28, 2002 8:36 am
by mydimension
while im still unsure about this, i think with register_globals on $_SESSION['Assn'] would be the same as $Assn. so setting one would change the other.

Posted: Thu Nov 28, 2002 8:50 am
by twigletmac
I'm with mydimension on this one, not entirely sure but if you've done:

Code: Select all

$_SESSIONї'Assn'] = 'something';
you've registered $Assn as a session variable because of register_globals being on. Basically you'll have to make sure that you use unique names for your session variables that you don't use anywhere else in your script except when setting or retrieving that session variable or turn reg_globals off.

Mac

Posted: Thu Nov 28, 2002 10:33 am
by BigE
One thing to understand with the new superglobals is that $_SESSION works exactly the way session_register() does. So if you use

Code: Select all

<?php
$_SESSIONї'Assn'] = 'something';
?>
then its the same as using

Code: Select all

<?php
$Assn = 'something';
session_register('Assn');
?>
Now due to register_globals being on, it has the same effect either way you do it, so $Assn will be the session variable. I hope that makes a little bit more sense. I also suggest that you read the manual a little more on sessions php.net/session