Right? As the question. Can cookiephp set in js be read? And vice versa, right? As the question. Can I read the cookie set by js in php? And vice versa.
Reply content:
Right? As the question. Can I read the cookie set by js in php? And vice versa.
One exception is written on the server.Cookie
If you addHttpOnly
, ThenCookie
Cannot be accessed in JS.
But written in JSCookie
Can be normally sent to the backend.
Yes. Js can usedocument.cookie
Access, php can be accessed through$_COOKIE
Global variable access.
The server can be readable. It depends on whether the browser's cookie will be placed in the http request header, that is, in the request-header.Cookie:foo=bar
Whether the request header carries a cookie value depends on whether the domain and path of the cookie match the current request path.
The cookie set by PHP is also the information in the corresponding header, that is,Set-Cookie:foo=bar;path=/;domain=expample
And other information, js can not be read, it also depends on whether the path of the current page matches the domain and path of the Cookie set by PHP.
Take a look at the network in the developer tool as follows:
Hope to help you O (∩ _ ∩) O
It involves the problem of access path and httponly parameter settings. For more information, see my blog http://blog.csdn.net/yunnysunny/article/details/7748106.
Before asking this question, you need to know where the cookie exists and how to obtain and store the cookie in JS and PHP. Then you will know.
Js can be accessed through document. cookie, and php can be accessed through the $ _ COOKIE global variable.