Forum Moderators: coopster

Message Too Old, No Replies

local variables of the same name as a session variable

         

artie2004

3:10 am on Dec 21, 2004 (gmt 0)

10+ Year Member



I have REGISTER_GLOBALS set to off and i have a local variable with the same name as a session variable. For example, i have a local variable $username and a session variable $_SESSION['username'] and when i assign the local variable $username a value, the session variable $_SESSION['username'] is also getting assigned this value. Does anyone know why this could be happening?

Kysmiley

4:07 am on Dec 21, 2004 (gmt 0)

10+ Year Member



I'm still new at this but I am under the impression that _session acts like a memory bank to hold the information set into the variables values from one page to the next and to the DB if needed until u close the _session it will hold this information. I have a session on one page because I Want to carry the name from one to the next so i can place it in a specific place with out having to have the user fill out the form again.
Hope this makes sence
pat

jollymcfats

4:39 am on Dec 21, 2004 (gmt 0)

10+ Year Member



Are you using
session_register()
? That links a global variable to $_SESSION with behavior like you've described.

artie2004

3:46 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Kysmiley,

Yes, you are correct.

No. I am not using session_register(), because when using $_SESSION you don't need to use session_register() according to the PHP manual.

jollymcfats

7:48 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Does it happen with this minimal test case?

minimal.php

<? 
session_start();
echo $_SESSION['username'] . '<br>';
$username = 'foo';
echo $_SESSION['username'];
?>

If not, I'd guess that you've got a

$username =& $_SESSION['username']
or
$_SESSION['username'] = $username
somewhere in your code.

artie2004

12:19 am on Dec 24, 2004 (gmt 0)

10+ Year Member



Thanks for trying to help out you guys. It's my fault. I thought I had register_globals disabled but it wasn't. So, problem solved. Happy Holidays!