Cookie set with javascript, not recognised with PHP (same domain and path)

Viewed 1548

These are my cookies:

My cookies

I'm running my website from my own computer using a WAMP server. I access my main page from http://127.0.0.1/Zulaijen/, and this is the javascript funcion to set the cookies (User and Session):

    function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "; expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + expires;
}

When I read them using javascript, it works fine. I get my session. Then I go to another PHP page named 'uploader.php' with this code:

if(!isset($_COOKIE['TestCookie']))
    setcookie("TestCookie", "Hello World!", time()+3600);
print_r($_COOKIE);
echo("Session: " . $_COOKIE['Session'] . "<br/>User: " . $_COOKIE['User'] . "<br/>");

And the result is:

Array ( [TestCookie] => Hello World! ) Notice: Undefined index: Session in D:\wamp\www\Zulaijen\uploader.php on line 30 Notice: Undefined index: User in D:\wamp\www\Zulaijen\uploader.php on line 30

Which means my PHP code is not reading the cookies I set with javascript. It only reads the one I set with my PHP code (TestCookie). And I don't understand why. They are within the same domain and the same path.

2 Answers
Related