Jump to content

How to get cookies to work in IE8


snakeman

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.