View Full Version : Best way to get back to search results page?

02-15-2010, 02:41 PM

I have a form that returns search results from a number of search parameters.
Each row has a link to a details page that selects the relevant info based on the id passed.

What is the best method to return from the details page to the results page, keeping the search results from last time?

I suppose I could pass all the parameters to the details page and then back again to the search page, but this is messy and requires even more validation/ protection against injection.

An alternative is to use $_SERVER['referer_url'] but I know if can be hit and miss.

I notice that ebay dont pass the search parameters to the details page via the URL. However the link back to search results on the details page has the search parameters in there. Session variable perhaps?

02-15-2010, 02:45 PM
Yes. Session is the good way to store all search parameters. Instead you can use cookies as well.

Passing all parameters in URL is not a good option as it will open some security holes so always use POST method.

02-15-2010, 04:38 PM
Would something like this do the job:

02-16-2010, 08:48 PM
Or back to the session approach...

should I pass each parameter from the URL (I use GET, not POST) into the session individually? Or can I pass the whole query string as one e.g

$_SESSION['search_results_querystring'] = $_SERVER['QUERY_STRING'];

Then on the details.php page have:

echo "<a href=\"results.php?".$_SESSION['search_results_querystring']."\">Back
to search results</a>";

Someone else suggested saving a cached copy of the results in a separate file. But I'm not sure how this would work with potentially hundreds of queries and any one time?