Posted in PHP onMay 07, 2013
form页面
<form action="login.php" method="post"> 用户名<input type="text" name="username"><br> 密码<input type="text" name="password"><br> 记住密码<input type="checkbox" name="jizhu" value="1"><br> <input type="submit"> </form> <a href="userinfo.php">用户信息</a> <?php session_start(); function p($arr){ echo "<pre>"; print_r($arr); echo "</pre>"; } p($_SESSION); p($_COOKIE); ?>
登录页面
<?php function p($arr){ echo "<pre>"; print_r($arr); echo "</pre>"; } 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'>请先登录</a>";exit; }else{ $_SESSION['username'] = $_COOKIE['username']; } } function p($arr){ echo "<pre>"; print_r($arr); echo "</pre>"; } ?> 2131231231 <a href="updateuserinfo.php">修改信息</a> <a href="logout.php">推出</a>
推出页面
<?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 "这里是信息"; } ?>
PHP 登录记住密码实现思路
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@