I have a index.php in the root folder dealing with all the commands. In page of url “root/?a=a&b=b”, I have a form for POST to add new item.
After submit the form, the page should be back to “root/?a=a&b=b” and a new item is shown (I currently use header(‘Location: ‘ . $_SERVER[‘HTTP_REFERER’])).
In the meantimes, there is a div in page “root/?a=a&b=b”. If the page comes back from submitting the form, it should be shown; otherwise (GET to this page), it should be hidden.
I currently add a “&success=true” at the end of the the url. But after submitting the form, there is a “&success=true” in the url, and if I refresh the page, although not coming back from submitting form, the div is still shown.
I wonder if there is a way to pass a variable instead of modifying the url after submitting the form. In addition, I don’t want to use $_SESSION.
Thanks for helping!
This is a common problem and the cleanest method I know to work around this when using Post-Redirect-Get is to set a cookie in the response to the POST and then immediately delete it in the response to the GET.