Simple php cookie User Login instance

Source: Internet
Author: User

One of the purposes of cookie is to store the user's password and id on a specific website. It is also used to store the preference of the start page. On websites that provide personalized viewing, your web browser will be asked to store these preferences using a small amount of space on your computer's hard drive. In this way, each time you log on to the website, your browser will check whether you have any pre-defined preferences (cookies) for the unique server ). If any, the browser sends the cookie to the server along with your webpage request. Microsoft and netscape use cookies to create a personal start page on their websites. Companies generally use cookies for the following purposes: online ordering systems, website personalization, and website tracking.

Set-cookie: name = value;
Expires = date;
Path = path;
Domain = domain_name;

Next let's take a look at the simple user login instance about cookies


Login. php Tutorial: Process Logon

The Code is as follows:
<? Php
If ($ _ post ['username'] = 'admin ')
{
Setcookie ('hahaha', 'gogogo ');
Header ("location: index. php ");
}
?>

Index. php.
The Code is as follows:

<? Php
If ($ _ cookie ['hahaha'] = 'gogogogo ')
{
Echo $ _ cookie ['hahaha'];
Echo 'cookie you set ';
}
Else
{
Echo 'you have not set cookies ';
}
?>


Login_frm.php. This is the logon window.
The Code is as follows:

<Html>
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = utf8"/>
</Head>
<Body>
<Form method = "post" action = "login. php">
User: <input type = "text" name = "username"/>
<Input type = "submit" value = "submit"/>
</Form>
</Body>
</Html>

 


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.