One of the uses of cookies is to store a user’s password and ID on a specific website. Also used to store start page preferences. On websites that offer personalized viewing, your web browser will be asked to use a small amount of space on your computer's hard drive to store these preferences. This way, every time you log into the website, your browser will check if you have any predefined preferences (cookies) for that unique server. If available, the browser sends this cookie to the server with your request for the web page. microsoft and netscape use cookies to create personal start pages on their websites. Common uses for companies to use cookies include: online ordering systems, website personalization and website tracking
set-cookie: name = value;
expires = date;
path = path;
domain = domain_name;
Let’s take a look at a simple user login example about cookies
login.php tutorial This is to handle login
The code is as follows:
if($_post['username'] = 'admin')
{
setcookie('haha','gogo');
header("location:index. php");
}
?>
index.php and see the effect again
The code is as follows:
if($_cookie ['haha'] == 'gogogo')
{
echo $_cookie['haha'];
echo 'You set a cookie';
}
else
{
echo 'You have not set cookies';
}
?>
login_frm.php This is the login window
The code is as follows:
< ;html>