Home > php教程 > php手册 > body text

php使用cookie保存用户登录的用户名实例,cookie用户登录

WBOY
Release: 2016-06-13 09:16:23
Original
757 people have browsed it

php使用cookie保存用户登录的用户名实例,cookie用户登录

本文实例讲述了php使用cookie保存用户登录的用户名的方法。分享给大家供大家参考。具体实现方法如下:

用户登录文件:login.php

复制代码 代码如下:



用户登录


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

用户名:

密码:

是否保存用户名:




后台文件:admin.php

复制代码 代码如下:

if(!empty($_POST['sub']) && $_POST['username']=="admin"){
 echo "欢迎".$_POST['username']." 登录成功";
 if(!empty($_POST['yes'])){
  setCookie("username",$_POST['username'],time()+3600*24*30);
 }else{
  setCookie("username","",time()-10);
 }
}else{
 echo "你的账号错误,请重新输入
";
}
echo "返回登录页面";
?>

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template