Query regarding sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rootuid
Forum Newbie
Posts: 2
Joined: Sun Jan 17, 2010 10:38 am

Query regarding sessions

Post 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:
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Query regarding sessions

Post by Eran »

On some operating systems, variables are case-sensitive. The session superglobal is $_SESSION (all caps) not $_session
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

Re: Query regarding sessions

Post 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 :]
rootuid
Forum Newbie
Posts: 2
Joined: Sun Jan 17, 2010 10:38 am

Re: Query regarding sessions

Post 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.
Post Reply