I have a website where my landing page could send the user to one of our locations. I am wondering if there is a way to store their location choice and redirect them to the correct location based on information I stored. I have seen this before on a lot of store pages where they keep and let you browse your local store. Would a cookie be the best way to store this information?
Cookies would be perfect for such a situation. Simply record the location id and then redirect to that place 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']]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With