Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Best way to get back to search results page?

    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?

  • #2
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Would something like this do the job:
    http://www.dezinerfolio.com/2008/01/...vious-page-php

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

    PHP Code:
    $_SESSION['search_results_querystring'] = $_SERVER['QUERY_STRING']; 
    Then on the details.php page have:

    PHP Code:
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •