tags:

views:

49

answers:

3

hi! i've a search bar from where users can search for videos.. after the search, the user goes on to click and watch a video(from the search result)..when the user hits the browser's back button it displays the following

To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

instead of just showing the results.. i just want to display the results of search when the user hits back..is it something related to cache? thankx..

+2  A: 

Preferably, change your search form's method to get, or use the Post/Redirect/Get pattern.

That message is displayed because POST data needs to be resent to re-render the page.

Dominic Rodger
+1 for mentioning PRG. Long live PRG!
thephpdeveloper
+2  A: 

If you don't want that, you can use GET instead of POST for your form method.

ie, you should use something like this :

<form action"yourpage.php" method="get">
    ...
</form>

instead of :

<form action"yourpage.php" method="post">
    ...
</form>


This way, the parameters used in the form will be sent in the URL, and not by POST, and users will be able to :

  • use back with no problem, independantly of the browser's cache
  • bookmark the result page (which is nice ^^ )


And I should add that, in theory :

  • POST has to be used when you want to create/modify data
  • and GET has to be used when you want to... well, get, data.

When searching for something via a search form, your users are not creating nor modifying data : they are asking for data -- so, your form should use the GET method.

Pascal MARTIN
A: 

No, it's not a cache issue. The problem is that you are using POST to submit the search form. There are a couple of solutions.

  • The better one is change the form to use GET. You can do that by setting its method attribute like

    <form method="get" action="search.php">
    
  • The other, if you fear that the search query will get way too long you can save the search with some form of id and then redirect to a page that fetches this search id and shows the result. Redirecting can be done with

    header('Location: show_search.php?id=' . $searchId);
    
Emil Ivanov