How do I make $ _POST permanent?

if I have a search function for my site and I want the custom search preferences to be available on any page of my site where a search module is available that I can imagine to convert the variable $_POST

to a cookie ... but I just change then which was already created by another person I replaced and I don't know if his other pages will affect this search module if I start relying on the cookie ... so I was trying to create a persistent array $_POST

from which I can work. Is it possible?

+1


source to share


2 answers


I would look at using $ _SESSION. Place all search items into an array in $ _SESSION.

to give you an example:

say the user is looking for "apples"

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



tell the user to then search for "oranges"

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

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

+10


source


You can either save the search query to session or to a cookie as you mentioned. If you want to code a search engine to handle both cases where there is a cookie and where there is no cookie, I don't think there should be a problem.



+3


source







All Articles