Why does the cookie value in PHP fail to be read?

Source: Internet
Author: User
Tags set cookie
Why does the cookie value in PHP fail to be read? In the same website, use setcookie ("userLogin", "TEST", time () + 60*60*24); the statement sets the cookie value, on this page, you can use echo $ _ COOKIE ["userLogin"]; to read data, but go to other pages of the same website and use echo $ _ COOKIE ["userLogin, is a null value. What is the problem?


Reply to discussion (solution)

The code you sent is tested by me and there is no problem. it may be that your testing method is faulty, your environment is faulty, or your program is affected by other code.

Cookie has a working path problem (the default is the current path)
That is, if you set the cookie in the subdirectory file, you can only see the set cookie variable in the subdirectory program.
In view of the large number of website files, it is unlikely that all files are stored in the root directory. therefore, set the 4th parameter of setcookie to/, even if the cookie is valid for the entire website.

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.