how to get cookies from a different domain with php and javascript

前端 未结 2 1512
再見小時候
再見小時候 2020-12-16 00:58

Suppose i have a cookie set in first.com say user. Now i want to read that cookie in second.com through javascript and ajax. But it is not working.I have got xmlHttp.status=

2条回答
  •  死守一世寂寞
    2020-12-16 01:27

    Your problem is that browsers wont let javascript to access different domain. Add:

    header('Content-type: text/html');    
    header('Access-Control-Allow-Origin: *');   
    

    lines to the beginning of cookie.php and it'll work. Still, you wont get the cookie (or at least in Chrome). I couldnt yet figure out why. It seems as if chrome creates a new session for the javascript and wont let that session access previous cookies. Like HttpOnly.

提交回复
热议问题