Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/71936-forms-session-and-header/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.