Javascript-js set the cookie PHP can read it? and vice versa.

Source: Internet
Author: User
Tags set cookie
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.

  • 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.