Session name as variable name

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
kingoftech
Forum Newbie
Posts: 1
Joined: Thu Mar 12, 2009 8:52 am

Session name as variable name

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Session name as variable name

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Session name as variable name

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Session name as variable name

Post 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!) :)
Post Reply