Home > Backend Development > PHP Tutorial > Simple php cookie user login example_PHP tutorial

Simple php cookie user login example_PHP tutorial

WBOY
Release: 2016-07-20 11:09:24
Original
902 people have browsed it

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>





User:
< input type="submit" value="Submit" />



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444813.htmlTechArticleOne of the uses of cookies is to store the user's password and ID on a specific website. Also used to store start page preferences. On sites that offer personalized viewing, your network will be asked to...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template