Jump to content

'back to Search Results' link


htcilt

Recommended Posts

Hi,

 

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? I'm not sure if I need to pass each parameter to the session independantly or if I can just do the whole query string e.g.

 

results.php

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

 

details.php

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

 

What is the best way to achieve this?

Link to comment
Share on other sites

Actually I said that wrong

 

The search query on my code is built from POST vars

so I save the whole POST array in the session, and restore as necessary

 

this is a snippet from my search results page

 

if(isset($_POST['search']) || isset($_GET['rerun']))
{
   if(isset($_POST['search']))  // either save postvars or reload for a rerun
      $_SESSION['postvars'] = $_POST;
   else
      $_POST = $_SESSION['postvars'];

Link to comment
Share on other sites

I need a little help understanding sessions when used in the search/detail example.

 

I dont understand the checking if the session name is already set or not.  Whether the session be run for the 1st time, or when coming back from the details page, the session data should always be $_GET.

 

Reading this tutorial:

http://www.tizag.com/phpT/phpsessions.php

 

The logic is:

if session name exists, do something

otherwise do something else.

 

As I want the session data to always contain $_GET values when going back and forth to the details page, I'm not sure if I would need to check if it is set or not?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.