Eric_S Posted November 13, 2011 Share Posted November 13, 2011 Hi, In my ErrorDocument I'd like to be able to set some variables for future use then redirect using header() and access them. .htaccess has this entry in it: ErrorDocument 404 /error.php I can pass variables in cookies and all works: setcookie('my_var', 'my_val'); header ("Location: $url"); I would rather set $_SESSION variables but I can't get it to work. session_start(); $_SESSION['my_var'] = 'my_val'; header ("Location: $url"); then... echo $_SESSION['my_var']; returns "". This works fine from other php scripts but not from ErrorDocument. What am I doing wrong here? .htaccess has this in it: ErrorDocument 404 /error.php TIA. Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/ Share on other sites More sharing options...
Eric_S Posted November 15, 2011 Author Share Posted November 15, 2011 The session is not getting passed to the next page. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/#findComment-1288206 Share on other sites More sharing options...
MasterACE14 Posted November 15, 2011 Share Posted November 15, 2011 do you have session_start(); at the top of the 'next page' ? Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/#findComment-1288210 Share on other sites More sharing options...
Eric_S Posted November 15, 2011 Author Share Posted November 15, 2011 Yes, it's there on both pages. Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/#findComment-1288261 Share on other sites More sharing options...
xyph Posted November 15, 2011 Share Posted November 15, 2011 You have to close the session before doing the redirect. This ensures the session is written to before the next page is served. session_write_close is probably the best idea. Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/#findComment-1288266 Share on other sites More sharing options...
Eric_S Posted November 16, 2011 Author Share Posted November 16, 2011 Tried that too. I figured out the session_id changes but how can I grab the one from the last page or keep that session in the first place? I can pass the session_id in the query string but that's ugly. I can use cookies too and that works but sessions or post would be best. Quote Link to comment https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/#findComment-1288602 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.