Page 1 of 1

Query regarding sessions

Posted: Sun Jan 17, 2010 4:33 pm
by rootuid
Hi,
I've a question regarding sessions, specifically declaring a variable in one php script and accessing it in another. The problem I'm facing is that the variable isn't recognised by the second php script.

test1.php

Code: Select all

 
<?php
session_start();
$_session['name']="tom";
echo $_session['name'];
?>
 
output

Code: Select all

 
tom
test2.php

Code: Select all

 
<?php
session_start();
echo $_session['name'];
?>
 
output

Code: Select all

 
Notice: Undefined variable: _session in /Applications/MAMP/htdocs/test2.php on line 3
php.ini:
register_globals Off Off
By echoing the session_id() I can confirm the same session exists in both scripts.

Any ideas whey $_session['name']; isn't identified in test2.php? Thanks in advance. :mrgreen:

Re: Query regarding sessions

Posted: Sun Jan 17, 2010 7:03 pm
by Eran
On some operating systems, variables are case-sensitive. The session superglobal is $_SESSION (all caps) not $_session

Re: Query regarding sessions

Posted: Sun Jan 17, 2010 7:07 pm
by mellowman
It most likely is that it is case sensitive...BUT if that doesn't work check to make sure in your browser that it is making a session with the name of your site :]

Re: Query regarding sessions

Posted: Mon Jan 18, 2010 10:39 am
by rootuid
Thank you both for your responses. I moved to a different platform and installed LAMP. I renamed the variables using capitals and it now works. Thanks again.