Prevent browser waring when you hit the 'go ba

2019-01-29 06:28发布

问题:

I have a little problem here. Actually, more of an annoyance.

I have a form on my index page that has a small search form:

<form action="search.php" method="post">
<input name="search" type="text" />
<input type="submit" name="submit">

now on the search.php file I just use the $_POST['search'] to retrieve the value that I'm searching. This file also displays the actual search results, which I can click on to go to that page.The search is actual done on the database. Also, because my search returns the top 10 random results from the DB, if I hit the 'back' button and confirm the warning, the search will be executed again, and will return a different set of results.

The problem, as you know, is that when you click on one of the search results and then hit 'back' on the browser, you get that browser warning about 'To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.'.

What's the easiest way to prevent this from happening? I looked into that PRG technique but I'm not sure how to implement that.

Any help would be great. Thanks. Bruno.

回答1:

Is it OK to use GET method here, users won't see warning if form sent by GET method.