The path to the cookie and the cookie domain

Source: Internet
Author: User

the path to the cookie and the cookie domain

Cookie Path

Cookies are typically created by the user accessing the page, but not only on the page where the cookie is created. By default, for security reasons, only pages that are in the same directory as the page in which the cookie was created or on the subdirectory where the cookie page was created are accessible. Then you need to set the path if you want its parent or the entire Web page to be able to use cookies.

A method of making the cookie for this setting accessible to other directories or to the directory of the parent:

Document.cookie = "UserName = Lone ice sea; path=/";

Cookie Domain

The path solves the problem of accessing cookies under the same domain, so how do you solve the access problem under the same primary domain? We can set it by specifying a host name that can access the cookie.

Document.cookie= "Name=value; Domain=cookiedomain ";

For example, "www.baidu.com" and "mp3.baidu.com" common an associated domain name "baidu.com", if we want to "www.baidu.com" cookies under "mp3.baidu.com" access, we need to use The domain property of the cookie, and you need to set the Path property to "/"

Here is a point to note: A certain is the access between the same domain, can not set the value of domain to the domain name of the non-primary domain.

The default cookie domain is the current domain name, and the default Path setting cookie is the current page's directory path. If you want to access a cookie across a domain or under another path, you must reset both properties, domain, and path.

www.baidu.com/content/example/3.jsp field domain is www.baidu.com, path is/content/example

Document.cookie = "username= lone ice Sea; path=/; Domain=baidu.com "

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.