Home > Backend Development > PHP Tutorial > PHP uses cookies to save user name instances for user login, cookie user login_PHP tutorial

PHP uses cookies to save user name instances for user login, cookie user login_PHP tutorial

WBOY
Release: 2016-07-13 10:09:01
Original
985 people have browsed it

php uses cookies to save user name instances for user login, cookie user login

The example in this article describes how PHP uses cookies to save the user name of the user's login. Share it with everyone for your reference. The specific implementation method is as follows:

User login file: login.php

Copy code The code is as follows:


User login


function getCookieUsername(){
if(empty($_COOKIE['username'])){
return "";
}else{
Return $_COOKIE['username'];
}
}
?>

Username:

Password:

Whether to save the user name:




Backend file: admin.php

Copy code The code is as follows:
if(!empty($_POST['sub']) && $_POST['username']=="admin"){
echo "Welcome".$_POST['username']." Login successful";
if(!empty($_POST['yes'])){
setCookie("username",$_POST['username'],time()+3600*24*30);
}else{
setCookie("username","",time()-10);
}
}else{
echo "Your account is wrong, please re-enter
";
}
echo "Return to login page";
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947914.htmlTechArticlephp uses cookies to save user login examples, cookie user login This article tells the example of php using cookies to save user logins username method. Share it with everyone for your reference. ...
Related labels:
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