COOKIE with the same name and path-php Tutorial

Source: Internet
Author: User
COOKIE in a project with the same name and different paths, multiple cookies are used to jointly determine the user status.
The background is as follows:

Userid usercode username

Three cookies. if both exist, check whether a session exists. Otherwise, the user is prompted to log on again after the COOKIE is deleted.

At first, I used JS to generate cookies. later, I used PHP to generate cookies for other reasons. during the test, I found that the endless loops of login and homepage

After checking the COOKIE, I found that the files generated using JS were still running in sub-directories during my test, so PHP did not clear them. after experiment and Baidu, I learned that

Multiple cookies with the same name and different paths
If the page is in the root directory, obtain
If the page is in a subdirectory, obtain

Http://jinnianshilongnian.iteye.com/blog/1656534 I know here
Use the tool/framework of java.net. HttpURLConnection. if multiple cookies with the same name in the same path are obtained, the first cookie is obtained;
Use apache HttpClient to obtain the last one in the same way as the browser.

That is to say, the latest COOKIE will be obtained.

However, I tested the results using IE and Google Chrome

The page under the subdirectory is obtained in the order that PATH is the COOKIE of the current directory, and then the upper-level directory is obtained no matter the time sequence. The method for obtaining the latest COOKIE is not followed.

Then I am confused. If PHP cannot find out which Directory the COOKIE is obtained according to the logic of my project, it will not be able to delete the COOKIE, and it will keep an endless loop... Solution


Reply to discussion (solution)

Different ?? Are there any differences ?,
For example:
Under? When cookie (actionType) is created. in firefox, if a cookie with the same name exists under/a, firfox will directly read the cookie under/a and ignore the cookie under/(that is, the parent path cookie ). that is to say, if/a's action is empty, firefox considers the action as Null, regardless of the cookie with the same name as the parent.

In comparison with ie, cookie (action) under ). when reading a cookie under/a, even if the cookie under/a is empty, ie reads the cookie of the same name as the parent, which is equivalent to combining the cookie of the parent path and the cookie of the sub-path. However, the cookie is read first.

Therefore, when using cookies, we try to ensure that the server sets a cookie.

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.