Jump to content

Forms, Session and Header


tempi

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.