Is that right? Title. JS Set cookie PHP can read it? and vice versa.
Reply content:
Is that right? Title. JS Set cookie PHP can read it? and vice versa.
There is an exception, the server-side write Cookie
if there is a plus, it is HttpOnly
Cookie
not accessible in JS.
But JS write Cookie
can be sent back to the normal.
Yes. JS can be document.cookie
accessed through the access, PHP can be $_COOKIE
accessed through global variables.
Server-side is not readable, in the browser's cookie, whether it will be placed in the HTTP request, that is Cookie:foo=bar
, Request-header, and the request header to carry a certain cookie value, Depends on whether domain and path of this cookie match the current request path.
The cookie set by PHP is also the information in the corresponding header, that is, the information in the Response-header, JS is not Set-Cookie:foo=bar;path=/;domain=expample
readable, and it depends on whether the path of the current page matches the domain and path of the cookie set by PHP.
Read more, the network in the developer tools
I hope I can help you. O (∩_∩) o
Involved in the access path problem, but also related to the HttpOnly parameter settings, specifically see my blog http://blog.csdn.net/yunnysunny/article/details/7748106
Before asking this question you need to know where the cookie exists, JS and how PHP gets and stores the cookie. And then I knew it.
JS can be accessed via Document.cookie, and PHP can be accessed by $_cookie global variables.