1

I have build a form that do nothing else than build a url to "redirect" the user, based on form element values.

The form contains values from a taxonomy that contains the Countries and the cities of each city.

So when the user choosing a country the form building the url that send the user to the appropriate page that display all the records of this country. If the user choose and the city field, then the form building the url that send the user to the appropriate page that display the records of this country > city.

The form it is using "post" as method.

All works fine untils here !.

The problem is when the user try to refresh the results page, or try to use the back button from a subsequent page.

To fix that, I try to redirect the user after submiting the form to the same form, but I am afraid for endless redirection. For this reason I like to know if it is posible to change the modify the request method via the header() function.

This can help me to check the $_SERVER[REQUEST_METHOD] if it is set to POST, thus do, the redirection.

KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166

1 Answers1

7

If you read up on HTTP headers, you'll know that header("Location: ...") sets a status code that explicitly causes the browser to use a GET request instead of whatever method it was using.

In fact, you have to manually set a status code of 308 if you want to force the browser to resend the request using the same method.

So, don't worry about it :)

phihag
  • 278,196
  • 72
  • 453
  • 469
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Also, you should `die()` or `exit()` immediately after `header('Location: ...')`; – Popnoodles Jan 10 '14 at 11:08
  • @phihag Can you provide some code showing how to manually set the status code of 308? – somejkuser Jul 29 '15 at 15:45
  • @jkushner This question deals with switching to a GET. If you want to send a 308 and don't know how to do it in php, why don't you [please do ask a new question](http://stackoverflow.com/questions/ask). That way, future searchers with the same problem will find your question and benefit from it. If you want, you can drop me a note with the new question's URL. – phihag Jul 29 '15 at 16:15