简体   繁体   中英

Cannot read cookie in Internet Explorer from PHP when script is loaded from another domain

Ok, this is a little complicated:

  1. I set a cookie on domain foo.com with php:

    header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); setcookie("c", "value", strtotime( '+30 days' ));

  2. I call the script <script src='http://foo.com/script.php'> from domain bar.com that loads a javascript file that is output through php

    header('Content-Type: application/javascript');
    echo $_COOKIE['c'];

Now, when I open http://foo.com/script.php in Chrome, Firefox, Edge or Internet Explorer, it will display value .
When I instead load the script from bar.com , it will also display value in Chrome, Edge(!) and Firefox, but in the Internet Explorer 10/11, the cookie is not set and cannot be read.

I do not understand why the cookie is not set in IE since I am loading the script from foo.com where the cookie was set initially. So, the script should have access to the cookie.

Any ideas highly appreciated.

What local domain names are you using to call these scripts?

I remember that IE is sometimes peculiar about domain names it accepts cookies for, they need to contain at least one dot . – names such a localhost tend to cause problems in that regard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM