Page 1 of 1

Session name as variable name

Posted: Thu Mar 12, 2009 9:07 am
by kingoftech
Session name as variable name problem
eg:
$_SESSION['user']="sample"; //this is session variable
$user="data"; // this is variable

when i get session value it will display variable value like this

echo $_SESSION['user'];

expeted result : sample

but it display : data
how?

Re: Session name as variable name

Posted: Thu Mar 12, 2009 9:56 am
by pickle
I think there's a setting in php.ini that automatically imports $_POST, $_GET, $_SESSION, and $_COOKIE variables into the local variable space - sort of like automatically calling extract($_POST), etc at the head of every file. I can't remember what the setting is though.

If you find it, you can either change php.ini, or call ini_set() to change that setting.

Re: Session name as variable name

Posted: Thu Mar 12, 2009 10:08 am
by Bill H
Or, if you are on a shared host and/or don't want to mess with php.ini settings, use variable names that are different from $_SESSION index names. But pickle is right, there is some such setting, and it can make you think you have gone nutzoid if you don't know about it.

Re: Session name as variable name

Posted: Fri Mar 13, 2009 5:14 am
by Jenk
pickle wrote:I think there's a setting in php.ini that automatically imports $_POST, $_GET, $_SESSION, and $_COOKIE variables into the local variable space - sort of like automatically calling extract($_POST), etc at the head of every file. I can't remember what the setting is though.

If you find it, you can either change php.ini, or call ini_set() to change that setting.
register_globals directive :) I hear will be removed in PHP6 (finally!) :)