Search code examples
javascriptinternet-explorercookiestrackingaffiliate

Cookies with expiration lost by IE6, IE7 when loaded by JS on a different domain


We trying to write an affiliate tracking system.

Users click on a link to a PHP script on server A that puts some cookies with tracking info. The script then redirects them to a landing page on server B. Once the user gets to a destination page a javascript generated by PHP code is loaded, using the previously set cookies.

This all works fine on Safari, FF, and IE9.

We had an issue on IE8 where the php that generates the javascript was only getting sent back cookies that were set without using any parameters other than name and value. Cookies that were given an expiration date were not sent back. This we eventually fixed by setting the cookie path to /, even though both of the php scripts ( the setter and the getter ) are in the same path. But that fix only worked for IE8, we still have the same problem with IE6 and IE7.

Also If we call the getter script directly ( not from a script tag on server B) then everything works as expected.

Also we have tried setting IE privacy settings to their lowest setting.

Example of how we are setting the cookies

 <?PHP
 setcookie($key,$val);//this works

 //this doesn't
 setcookie('COOKIE', json_encode($info), time()+259200000);

Solution

  • Ok so the sorter cookie time fixed for IE7 but not for IE6

    For IE6 we needed to use P3P headers, I put them on both the script that writes the cookie and that reads the cookie.

    <?PHP
    header('Cache-Control: public, max-age=0, must-revalidate');
    header('P3P: policyref="/p3p.xml", CP="NOR NOI DSP COR ADM OUR PHY"');
    

    We might have only needed it on the script that writes the cookie, but now it works so I'm not going to mess with it if I don't have too.