Redirecting a user to a website based on stored cookie information

I have a website where my landing page can send a user to one of our places. I am wondering if there is a way to save their place selection and redirect them to the right place based on the information I saved. I have seen this before on many pages of the store where they are stored, and allows you to browse your local store. Would a cookie be the best way to store this information?

+4
source share
1 answer

Cookies would be ideal for such a situation. Just write down the location id and then redirect it next time!

// store an array of location cookie names and there location values $places = array('us'=>'/united-states.php'); // After user chooses a location, store the cookie based on his choice: in this case, us! setcookie('location','us', time() + (3600 * 24 * 7)); // On a new page check the cookie is set, if it is then redirect users to the value of that cookie name in the array! if(isset($_COOKIE['location'])){ header('Location: '.$places[$_COOKIE['location']]); } 
+9
source

All Articles