Forum Moderators: coopster

Message Too Old, No Replies

printing a session variable

         

thebigstar

10:31 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



when i set a session variable like

$_SESSION['name']=tom;

then i try to print this variable later on the page,

print $_SESSION['name'];

it print nothing.............i cant figure out why this happens

any help would be wonderful

ergophobe

10:48 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How do you have error reporting set? Set to E_ALL in php.ini or in your script using

ini_set()

I ask because

1. This

$_SESSION['name']=tom;

should give you an undefined constant warning. Since tom is not defined, it would indeed be empty. You need:

$_SESSION['name']="tom";

2. You may not have sessions started. You should nevertheless be able to use a variable named $_SESSION['name'] but it would have no special meaning in that case.

thebigstar

10:57 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



well its more like #_SESSION['name']=$user;

and the $user is set by the $_POST['user']

and yes the session is started

im not sure if i have the error reporting set or not i will have to look in to that

ergophobe

5:11 pm on Dec 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, maybe the post data isn't coming through. Have you run a

print_r($_POST);

and verified that the original post variable is set?