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.