Can cookiephp set in javascript-js be read? And vice versa

Source: Internet
Author: User
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.CookieIf you addHttpOnly, ThenCookieCannot be accessed in JS.
But written in JSCookieCan be normally sent to the backend.

Yes. Js can usedocument.cookieAccess, php can be accessed through$_COOKIEGlobal 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=barWhether 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=expampleAnd 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.