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>