Do a login interface, automatically remember the user name function
if (Empty ($_post[' Chkremember ')) {
The user does not select the Radio box
if (!empty ($_cookie[' username ')) {
Setcookie (' username ', ', Time ()-100);
}
}else{
User Select a Radio box
Setcookie (' username ', $username, Time () +7*24*3600);
}
When the user has selected a box that remembers the user's name, the cookie has been saved in C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\ There is a cookie file (Administrator@localhost[1].txt) Under the Cookies menu, and the content is correct.
But reading the cookie is unsuccessful, and each time it returns control
function Getcookieval ($key) {
if (Empty ($_cookie[$key])) {
return "None";
}else{
return $_cookie[$key];
}
}
?>
Direct Print COOKIE array print_r ($_cookie);
The resulting empty array is also
What's going on here?
is the cookie save path inconsistent with the read path?
Reply to discussion (solution)
Should be returned every time empty value, I typo.
1.
Setcookie (' username ', $username, Time () +7*24*3600);
And
Getcookieval ("username")
Must be in a different HTTP session
2. You do not specify a path when setting a cookie
So the cookie is only valid on the path where the Setcookie program is executed.
If the program executing the getcookieval is not under the same path, the value will not be taken
Setcookie (' username ', $username, Time () +7*24*3600, '/');
This allows the cookie variable username to be valid throughout the site.
Thank you, Hero, saved!