htcilt Posted February 16, 2010 Share Posted February 16, 2010 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? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 what I do, is store the original constructed query in the session, so it can be reissued on return to the results page. you just need a flag to say to use the stored query or not Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 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']; Quote Link to comment Share on other sites More sharing options...
htcilt Posted February 16, 2010 Author Share Posted February 16, 2010 Thanks jl5501, Its looking like sessions is the way to go Quote Link to comment Share on other sites More sharing options...
htcilt Posted February 17, 2010 Author Share Posted February 17, 2010 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.