Jump to content

header location requires POST variables again


nickelus

Recommended Posts

is there a way to redirect a user back from a processing page to the previous page (that requires POST variables again) without using sessions or is there a better way to accomplish this. I've been thinking about re-posting the data on the processing page and header() to redirect but it doesn't sound efficient.

Link to comment
Share on other sites

If you use header() you lose anything that was posted or that was part of the query part of the url. The only way is to include the previous page in the processing page or vice versa. You are probably referring to a form and a processing page and you want to send them back if an error occured but the fields have to be left filled in.

 

Just include the processing page on the form page. This way you keep the php minimal amongst the html. It's a struggle we all fought and the best approach are view helpers. These little bastards are allowed to spit out html (as they are designed for this specific purpose) and allows us to work with models in a clean php fashion (with no html mess). These models then use these view helpers to properly render their contents in the view.

Link to comment
Share on other sites

If you use header() you lose anything that was posted or that was part of the query part of the url.

Not at all. Change the script requiring the POST data to use:

// from $_POST['varname'] to
$_REQUEST['varname'];

 

Then you can use paramaters within the url i.e.

header("Location:page.php?varname=".$_REQUEST['varname']);

However if you are posting text strings then I do not recommend. Either apply a better design to your code or stor the data within a session after it has been posted.

Link to comment
Share on other sites

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.