tempi Posted October 5, 2007 Share Posted October 5, 2007 Hi there, Is it possible, that a redirect with header("location:X") destroys the postvars? I have site 1.php with a form field: <input name="firstname" type="text" value="<?=$_SESSION['firstname']?>"> Now I post that Field on 2.php where I want to save it in the session and redirect back: $_SESSION['firstname'] = $_POST['firstname']; header ("Location: 1.php?".session_name()."=".session_id()); The Sessionvar "firstname" isn't set on the 1.php now - why? I read, that header-redirects loses the session ID so I put them in the URL. Still kinda doesn't work. Any suggestions? Thanks Tempi Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/ Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 I've used redirect via header() and never had a session ID destroyed...!? Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-362412 Share on other sites More sharing options...
tempi Posted October 5, 2007 Author Share Posted October 5, 2007 Well I think the problem is, that the postvars aren't posted correctly because of the redirect. So they won't be saved in the sessionvar. So finally it's maybe not a session-problem but a post-problem?! Did anyone experience something like that? Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-362435 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 If you use header() to redirect a user to a new page then yes, the POST vars will be lost. Either pass the data in the URL or look at handling the data differently. $_GET: Get the variables from the URL $_POST: Get the variables from a form $_REQUEST: Use either above method but I'm not sure which takes precedence if you have POST and GET with the same name. Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-362439 Share on other sites More sharing options...
tempi Posted October 5, 2007 Author Share Posted October 5, 2007 But if I save my Postvar into the sessionvar before I redirect with header() - why is it still lost? Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-362451 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Be sure to add session_start() at the start of each script. Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-362452 Share on other sites More sharing options...
tempi Posted October 8, 2007 Author Share Posted October 8, 2007 yeah I certainly did that. Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-364466 Share on other sites More sharing options...
tempi Posted October 9, 2007 Author Share Posted October 9, 2007 Am I totally wrong? Quote Link to comment https://forums.phpfreaks.com/topic/71936-forms-session-and-header/#findComment-365188 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.