Krash Posted June 3, 2010 Share Posted June 3, 2010 Can't get this to work. Here's the typical sample code - page1.php: <?php session_start(); $_SESSION['filename']='file.txt'; echo "page 1<br>filename = " . $_SESSION['filename']; echo "<br><a href='page2.php'>page 2</a>"; ?> page2.php: <?php session_start(); echo "page 2<br>filename = " . $_SESSION['filename']; echo "<br><a href='page1.php'>page 1</a>"; ?> $_SESSION['filename'] echos in page 1, but is blank in page 2. Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 3, 2010 Share Posted June 3, 2010 For debugging purposes, add the following three lines of code starting on the line immediately after your <?php tag in both files - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); You should actually have the error_reporting/display_errors settings already set to those values on your development system so that php will help you when developing and debugging php code. Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/#findComment-1067286 Share on other sites More sharing options...
Krash Posted June 3, 2010 Author Share Posted June 3, 2010 Here's what I get back - Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_a5afedd57f71750eef45b2d5cc870fe4, O_RDWR) failed: No such file or directory (2) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php:6) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php:6) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6 page 1 filename = file.txt page 2 // Warning: Unknown(): open(/var/php_sessions/sess_a5afedd57f71750eef45b2d5cc870fe4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0 Is that a server problem? Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/#findComment-1067295 Share on other sites More sharing options...
BizLab Posted June 3, 2010 Share Posted June 3, 2010 it means you have the wrong file path for your session folder. Echo this echo session_save_path(); That will give you the actual save path for your session folder. You can also find this info in your php_info() page - - seen when you place php_info(); This will show you all your current server settings. Also, you should check to be sure the start_session() function is run before ANYTHING else on the page. That may be why you are getting the header sent error... although, i have gotten that error when certain php functions (notably the unlink() function) are trying to send back errors which is why we use the error suppression (@) method.. but this is not likely your issue with the session. If you are in Linux and have access to the file permissions, you may want to open them up a bit more to a chmod 775 or something of the sort. Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/#findComment-1067384 Share on other sites More sharing options...
Krash Posted June 3, 2010 Author Share Posted June 3, 2010 There's nothing in the test files other than what I posted above, so nothing is being sent that should cause a header editor. I have the session_save_path - what do I do with it? Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/#findComment-1067430 Share on other sites More sharing options...
BizLab Posted June 10, 2010 Share Posted June 10, 2010 Compare it to the open dir path in your error logs. you will have to debug from there. Your open file path needs to match the session save path Quote Link to comment https://forums.phpfreaks.com/topic/203780-unable-to-pass-_session-variables-between-pages/#findComment-1070546 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.