As we all know, cookies are not connected or missing in Web page writing, today we talk about how to use cookie technology to save user login account
1. First, whether to save the user login account is the user's own decision, so we need to set a check box in the user login interface, so as to obtain the user's wish information, in order to provide a basis for the next operation.
Require_once ' common.php ';
User account: </td><td><input type= "text" name= "id" value= "<?php echo getcookievalue (" id ")?>" >
Save user account <input type= "checkbox" Name= "Keepid"/>//login.php
2. When the user decides to save the account information, how do we perform the Setcookie () operation on this basis?
$id =$_post[' id '];
if (!empty ($_post[' keepid ')) {
Setcookie ("id", $id, Time () +7*24*3600);
}else{
if (!empty ($_post[' id '))) {//If the user account has not been saved previously, then you need to clear the saved $_cookie[' ID ' if you previously chose to save it.
Setcookie ("id", "", Time ()-100);
}}
3. How do we display the saved account information in the Account box on the login page? Here, write a small function in the common.php.
function Getcookievalue ($key) {
if (!empty ($_cookie[$key])) {
return $_cookie[$key];
}else {
Return "";
}}
How to use cookies to save a user's login account