Jump to content

Sessions. Very simple question ... please help.


chunk

Recommended Posts

I can't get sessions to work. Ive reduced what i'm trying to do down to the most simple level:

 

page1.php

 

<?php

session_start();

$_SESSION['username'] = "UserOne";

echo $_SESSION['username'];

echo "<br><a href='page2.php'>Go to another page</a>";

?>

 

page2.php

 

<?php

session_start();

echo $_SESSION['username'];

?>

 

All that ever happens is that you click on the link to page 2 (from page 1) and you get a blank page.

 

No matter what I do, I cant access the session variable in page 2, that I can on page 1.

 

Can anyone help? Thanks.

Link to comment
Share on other sites

Is that really all that's on page2? If there is still more code, a blank page could mean you have a fatal error, but don't have error reporting on.

 

That is all thats on page two. Like I said, ive reduced it right down to the bare minimum so that all other causes of a problem can be ruled out.

 

create a file on your sever called phpinfo.php

copy and paste this in:

<?php

phpinfo();

?>

 

and access this page, I can take a look if you give the link

 

sessioninfo.jpg

Link to comment
Share on other sites

sessions don't last between subdomains - are you going from www.domain.com to domain.com (no www?)

try placing print_r($_SESSION); on both pages?

 

Not going between subdomains no.

 

print_r($_SESSION) on page 1 gives me: ( [username] => UserOne )

print_r($_SESSION) on page 2 gives me: Array ( )

 

Somebody has the same problem before.

He said if he commented out the session.save_path from php.ini, it works.

 

change

session.save_path to

;session.save_path

 

in your php.ini

 

Tried it. Makes no difference. :(

Link to comment
Share on other sites

ok,

 

now try change your session.save_path to a valid writeable directory.  Do not comment it out.

 

Got it to work. I commented it out, but forgot to restart my web server.

 

Commenting it out and restarting made it work.

 

Thanks very much!

 

Can I ask, is it a good idea to just comment it out or is it better to change it to something that is valid.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.