tags:

views:

125

answers:

2

if i have a search function for my site and i want the user's former search preferences to be available at any page on my site where the search module is available all i can think of is to convert the $_POST variable to a cookie... but i am just modifying what was already constructed by another person whom i replaced, and i dont know if his other pages dependent on that search module would get affected if i started to rely on the cookie... so i was trying to create a persistent $_POST array from which i can work with.. is it possible?

+3  A: 

You can either persist the search query to a session or to a cookie, as you mentioned. If you make sure to code the search module to handle both cases where there is a cookie and where there is not a cookie, I don't think there should be a problem.

Brian Fisher
+9  A: 

I would look into using $_SESSION. Put all the search items into an array in $_SESSION.

to give you an example:

say a user searches for "apples",

add it to $_SESSION['search_items'][] = "apples";

say the user then searches for "oranges",

add it to $_SESSION['search_items'][] = "oranges";

make sure you have session_start(); at the top of every page you plan on using the search functionality. then you can add and access the search items in $_SESSION

mmundiff