How to use cookies to save a user's login account

Source: Internet
Author: User
Tags setcookie

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

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.