Solarpitch Posted January 8, 2008 Share Posted January 8, 2008 Hey Guys, I had a post on this the other day in relation to assigning a variable to a session, just when I thought it was sorted... something went out of place. If you look at the below code, the variables seem to assign to the sessions fine when the "header(locat..." is commented out. However, when I put the header location.... in the script, the sessions wont take the values of the variables... its a little strange. step1.php... <?php ob_start(); session_start(); $process = isset($_POST['process']) ? $_POST['process'] : ''; if ($process != "execute") { //not being submitted... } else { $firstname = $_POST['firstname']; $_SESSION['firstname'] = $firstname; $lastname = $_POST['lastname']; $_SESSION['lastname'] = $lastname; header("Location: step2.php"); // The code works when this is commented out. ob_flush(); } ?> Note that step 2 page has excatly the same code as above, except it has a header location pointing to step 3 and so on. So it seems to work when the page doesnt get directed to step2.php after the form has been submitted. Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/ Share on other sites More sharing options...
stuffradio Posted January 8, 2008 Share Posted January 8, 2008 Try putting ob_flush(); above the header line. Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434067 Share on other sites More sharing options...
Solarpitch Posted January 8, 2008 Author Share Posted January 8, 2008 I tried that already I am afraid... but still no joy :'( Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434079 Share on other sites More sharing options...
Solarpitch Posted January 8, 2008 Author Share Posted January 8, 2008 Actually... that works but I get the message... Warning: Cannot modify header information - headers already sent by (output started at D:\hshome\account\tep1.php:36) in D:\hshome\account\step1.php on line 37 Line 37 ob_flush(); header("Location:step2.php"); <--- Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434085 Share on other sites More sharing options...
stuffradio Posted January 9, 2008 Share Posted January 9, 2008 Yeah, I'ms till having problems with headers. I'm trying to find a solution that lets me have multiple headers in a page. Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434092 Share on other sites More sharing options...
mrdamien Posted January 9, 2008 Share Posted January 9, 2008 What if you get rid of output buffering? Remove: ob_start(); and ob_flush(); It seems pointless in this situation anyways... Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434098 Share on other sites More sharing options...
sdi126 Posted January 9, 2008 Share Posted January 9, 2008 Try this: session_write_close(); header('Location: http://mysite.com/somepage.php'); exit(0); The session might not be complete before the next page tries to read it. If this doesn't work I have other suggestions to as this has happened to me before :-\ Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434113 Share on other sites More sharing options...
Solarpitch Posted January 9, 2008 Author Share Posted January 9, 2008 You little gem! Works perfect! Thanks man Quote Link to comment https://forums.phpfreaks.com/topic/85103-solved-problem-assigning-variables-to-a-session/#findComment-434614 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.