6

I'd like to know how to implement 303 redirect for displaying post data.

Example:

I send the form.

Redirect

Page displays the info I just posted. (Eg: Name, email).

I think it is done with parameters, like /index.php?name=TheName&email=theEmail but i'm not sure, since I've tried to find some good article explaining it but couldn't.

Thanks a lot.

JorgeeFG
  • 5,651
  • 12
  • 59
  • 92
  • @Daedalus Hi, I didn't tried yet, because I prefer to inform better first. I just saw articles, wikipedia etc, about what does the 303 redirect and why it's recommended, but didn't see a code example, on how to retrieve data. I didn't say that isn't viable, just want to know hows the way it's meant to be. Thanks – JorgeeFG Oct 21 '12 at 23:26
  • So to make sure I understand you, @Jorge, you want to retrieve information sent by a form, but the method of sending it doesn't matter(aside from it being POST, that is)? – Daedalus Oct 21 '12 at 23:42

2 Answers2

14

In PHP you can perform a 303 redirect using header():

header("HTTP/1.1 303 See Other");
header("Location: http://$_SERVER['HTTP_HOST']/new/location/here");

The problem you may face is retaining the form information after the redirect. One solution might be using PHP session variables to store the form data.

You could redirect using parameters to pass the submitted data, but that isn't what I'd consider a 'clean' solution.

Xenon
  • 3,174
  • 18
  • 37
1

You can do it other ways rather then passing the parameters in the url.

  1. Send the form.
  2. After checking valid values, Store the result in a database, session as you would normally do.
  3. Redirect
  4. Retrieve from the database or session.
  5. Use htmlentities() on the output.
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106