Unable to print out session variables

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
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Unable to print out session variables

Post by impulse() »

I have checked that sessions are enabled in the php.ini file, which it is, and I'm unable to print out any data stored inside of the $_SESSION variable.

On page example1.php I have:

Code: Select all

session_start();
$_SESSION["Name"] = "Stephen"; 
echo $_SESSION["Name"];


And on page example2.php I have:

Code: Select all

session_start();
echo $_SESSION["name"];
Can you see what I'm missing or where I'm going wrong?

Regards,
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

1. you don't need to openthe session each time if it's being included into that page.
2. name should be the same case as the actual index

so the second page should be "Name" not "name"
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Ahh, I should've spotted that one :)

Even still it doesn't display anything though.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

print_r($_SESSION);
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Still nothing.

It could be because I have to access my site through an online proxy. If I go straight to my domain or IP I get my routers setup page. Would you mind trying for me.

http://stesbox.co.uk/php/session.php - Creates session variable on this page, also shows it.
http://stesbox.co.uk/php/session2.php - Echo and print_r the session variable.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Is the session being created/ stored in the first place?

maybe your using a lower version and should be HTTP_SESSION_VARS?


Edit::: ok i just checked it out...its working sor i guess its that proxy thingy whatever...
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post by SpecialK »

Both of those links print out 'Stephen' for me.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Why don't you setup a webserver on your local pc?
e.g. with http://www.apachefriends.org/en/xampp.html
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Aaahh xampp...its good...sigh :)
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Don't know. It'll just be hassle to FTP over the complete files to the live web server once they're complete.
I'm writing 2-3 full working scripts at the minute and loads of few lines scripts for learning and testing.
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

btw, i was having serious session/cookies problems when i was creating my system locally. make a quick script to delete your sessions and clear your cookies and everything on your browser(s)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

impulse() wrote:Don't know. It'll just be hassle to FTP over the complete files to the live web server once they're complete.
I'm writing 2-3 full working scripts at the minute and loads of few lines scripts for learning and testing.
And why do you want to upload your two-lines-learning-scripts to a "live server"?
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Post by panic! »

I always prefer to write local and upload when finished if possible. Waiting 5 seconds to upload every time you make a little change and then having to load the page from the server is a pain.
Post Reply