snakeman Posted August 21, 2010 Share Posted August 21, 2010 I've placed some simple cookie handling code in a site to keep track of the last site visited between 2 choices on the main site. Here's the code in the header of the main site to check and change the cookie when the site changes. Thanks for any insights. ;-) if($_REQUEST['site'] == 'sitea'){ setcookie('location', 'sitea',time()+60*60*24*365); header("Location: http://www.sitea.com"); exit; } if($_REQUEST['site'] == 'siteb'){ setcookie('location', 'siteb',time()+60*60*24*365); header("Location: http://www.siteb.com"); exit; } if(isset($_COOKIE['location'])) { if($_COOKIE['location'] == 'sitea') { header("Location: http://www.sitea.com"); exit; } if($_COOKIE['location'] == 'siteb') { header("Location: http://www.siteb.com"); exit; } } This code seems to work in FF and Chrome as far as I can tell. Then again, it seems to work on my own computer with IE8 but does not on anyone else's computers I've asked to check it out on. Link to comment https://forums.phpfreaks.com/topic/211393-how-to-get-cookies-to-work-in-ie8/ Share on other sites More sharing options...
metrostars Posted August 22, 2010 Share Posted August 22, 2010 I've not done PHP for a while so forgive me if I'm wrong. You can only use the cookies on the domain you set them on. i.e. If you set the cookie on sitea.com, then you cannot access this cookie from siteb.com and vice versa. I think you'll have to look into databases and IPs to get what you want. Or set a file in sitea.com to handle all cookie set functions for both sites. Link to comment https://forums.phpfreaks.com/topic/211393-how-to-get-cookies-to-work-in-ie8/#findComment-1102312 Share on other sites More sharing options...
snakeman Posted August 22, 2010 Author Share Posted August 22, 2010 I'm only setting a cookie and changing that cookie on the main site, let's call it, main.com. So when you go back to main.com after closing your browser, you'll be directed to either sitea.com or siteb.com, the last site you were on. The code I included is on main.com and there's a form on each of the other sites that uses main.com to process the form submit choosing the other site. Does this make sense? Link to comment https://forums.phpfreaks.com/topic/211393-how-to-get-cookies-to-work-in-ie8/#findComment-1102449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.