chunk Posted February 9, 2007 Share Posted February 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 Have you check if session are enabled? Quote Link to comment Share on other sites More sharing options...
chunk Posted February 9, 2007 Author Share Posted February 9, 2007 Have you check if session are enabled? Ive tried to read through documentation and as far as I can tell, yes they are. Could you help me to check please? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
chunk Posted February 9, 2007 Author Share Posted February 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 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? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
chunk Posted February 9, 2007 Author Share Posted February 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 What version of PHP is this? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 ok, now try change your session.save_path to a valid writeable directory. Do not comment it out. Quote Link to comment Share on other sites More sharing options...
chunk Posted February 9, 2007 Author Share Posted February 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 it is better to point to a valid directory. if you commented it out, it would use cookie to store session data. and personally, I think it is not safe to use cookie to store session data at all. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 Yeah you need a valid dir. Users can easily edit cookie data, and if they have cookies blocked, your sessions won't work. Quote Link to comment Share on other sites More sharing options...
chunk Posted February 9, 2007 Author Share Posted February 9, 2007 Ok, thanks. So what would make a good valid dir? Something in my apache web server folder where my php files are? Quote Link to comment Share on other sites More sharing options...
hvle Posted February 9, 2007 Share Posted February 9, 2007 any local directory would do fine, it's your call Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.