PHP 实现登录记住密码
form页面
用户信息 "; print_r($arr); echo ""; } p($_SESSION); p($_COOKIE); ?><br> 登录页面 <p></p> <p></p> <pre name="code" class="php"><?php function p($arr){ echo "<pre class="brush:php;toolbar:false">"; print_r($arr); echo ""; } 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");<?php session_start(); echo "先关闭浏览器,在访问form.php 试试,然后 点推出在关闭浏览器试试"; p($_SESSION); p($_COOKIE); if(empty($_SESSION['username'])){ if(empty($_COOKIE['username'])){ echo "<a href='form.php'>请先登录";exit; }else{ $_SESSION['username'] = $_COOKIE['username']; } } function p($arr){ echo "<pre class="brush:php;toolbar:false">"; print_r($arr); echo ""; } ?> 2131231231 修改信息 推出
<?php session_start(); unset($_SESSION['username']); unset($_SESSION['password']); setcookie('username','',0); setcookie('password','',0); header("location:form.php"); ?>
<?php session_start(); if(empty($_SESSION['username'])){ echo "请先登录"; }else{ echo "这里是信息"; } ?>