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

PHP 登录记住密码实现思路

WBOY
Release: 2016-06-13 11:52:49
Original
774 people have browsed it

form页面

复制代码 代码如下:



用户名

密码

记住密码



用户信息
session_start();
function p($arr){
echo "
"; <br>print_r($arr); <br>echo "
Copy after login
Copy after login
Copy after login
";
}
p($_SESSION);
p($_COOKIE);
?>

登录页面

复制代码 代码如下:


function p($arr){
echo "

"; <br>print_r($arr); <br>echo "
Copy after login
Copy after login
Copy after login
";
}
session_start();
//p($_POST);
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
if($_POST['jizhu']){
setcookie('username',$_POST['username'],time()+60);
setcookie('password',$_POST['password'],time()+60);
}
header("location:form.php");

用户信息页面

复制代码 代码如下:


session_start();
echo "先关闭浏览器,在访问form.php 试试,然后 点推出在关闭浏览器试试";
p($_SESSION);
p($_COOKIE);
if(empty($_SESSION['username'])){
if(empty($_COOKIE['username'])){
echo "请先登录";exit;
}else{
$_SESSION['username'] = $_COOKIE['username'];
}
}
function p($arr){
echo "

"; <br>print_r($arr); <br>echo "
Copy after login
Copy after login
Copy after login
";
}
?>
2131231231
修改信息
推出

推出页面

复制代码 代码如下:


session_start();
unset($_SESSION['username']);
unset($_SESSION['password']);
setcookie('username','',0);
setcookie('password','',0);
header("location:form.php");
?>


修改用户信息页面

复制代码 代码如下:


session_start();
if(empty($_SESSION['username'])){
echo "请先登录";
}else{
echo "这里是信息";
}
?>

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