04-使用cookie实现记录用户名称的需求
2013-08-16 20:31
429 查看
login.php
<?php
require_once 'common.php';
?>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</head>
<img alt="logo.gif" src="./images/logo.gif">
<hr />
<h1>管理员登录系统</h1>
<form action="loginProcess.php" method="post">
<table>
<tr>
<td>用户id</td>
<td><input type="text" name="id"
value="<?php
echo getCookieVal ( 'id' )?>" /></td>
</tr>
<tr>
<td>密 码</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="keep" value="yes" />是否保存用户ID</td>
</tr>
<tr>
<td><input type="submit" value="用户登录" /></td>
<td><input type="reset" value="重新填写" /></td>
</tr>
</table>
</form>
<?php
header ( "content-type:text/html;charset=utf-8" );
if (! empty ( $_GET ['errno'] )) {
$errno = $_GET ['errno'];
if ($errno == 1) {
echo "<font color='red' size='3'>你的用户名或密码错误</font>";
}
}
?>
<hr />
<img alt="foot.jpg" src="./images/foot.jpg">
</html>
loginProcess.php
//3.获取用户是否选中了保存id
if(empty($_POST['keep'])){
if(!empty($_COOKIE['id']))
//删除cookie
setcookie("id",$id,time()-100);
}else{
//设置cookie
setcookie("id",$id,time()+7*2*24*3600);
}
common.php(获取cookie的方法)
function getCookieVal($key) {
if (empty ( $_COOKIE [$key] )) {
return "";
} else {
return $_COOKIE [$key];
}
}
<?php
require_once 'common.php';
?>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
</head>
<img alt="logo.gif" src="./images/logo.gif">
<hr />
<h1>管理员登录系统</h1>
<form action="loginProcess.php" method="post">
<table>
<tr>
<td>用户id</td>
<td><input type="text" name="id"
value="<?php
echo getCookieVal ( 'id' )?>" /></td>
</tr>
<tr>
<td>密 码</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="keep" value="yes" />是否保存用户ID</td>
</tr>
<tr>
<td><input type="submit" value="用户登录" /></td>
<td><input type="reset" value="重新填写" /></td>
</tr>
</table>
</form>
<?php
header ( "content-type:text/html;charset=utf-8" );
if (! empty ( $_GET ['errno'] )) {
$errno = $_GET ['errno'];
if ($errno == 1) {
echo "<font color='red' size='3'>你的用户名或密码错误</font>";
}
}
?>
<hr />
<img alt="foot.jpg" src="./images/foot.jpg">
</html>
loginProcess.php
//3.获取用户是否选中了保存id
if(empty($_POST['keep'])){
if(!empty($_COOKIE['id']))
//删除cookie
setcookie("id",$id,time()-100);
}else{
//设置cookie
setcookie("id",$id,time()+7*2*24*3600);
}
common.php(获取cookie的方法)
function getCookieVal($key) {
if (empty ( $_COOKIE [$key] )) {
return "";
} else {
return $_COOKIE [$key];
}
}
相关文章推荐
- js技术--cookie基础(封装cookie、使用cookie记录上一次用户登录名)
- 使用Cookie和JSON记录用户最近浏览历史
- 使用cookie实现记录上一次的登录名和密码
- 使用Cookie实现商品的浏览记录功能
- 使用Cookie和JSON记录用户最近浏览历史
- 黑马程序员__使用cookie记录用户访问次数 .
- java 使用Cookie实现,浏览过商品记录
- 使用cookie记录最后一次用户访问网站的时间
- python3下使用scrapy实现模拟用户登录与cookie存储—— 中级篇(百度云俱乐部)
- 在MySQL中使用init-connect与binlog来实现用户操作追踪记录
- 使用cookie+工具类实现的 记录显示 用户【浏览商品记录】
- 使用cookie技术实现大型网站购物网站的商品浏览记录
- 使用cookie,session,filter等技术实现用户自动登录
- [EntLib]微软企业库5.0 学习之路——第九步、使用PolicyInjection模块进行AOP—PART4——建立自定义Call Handler实现用户操作日志记录
- java 使用cookie记录用户上一次访问的时间 记住 用户的 登录名
- python3下使用scrapy实现模拟用户登录与cookie存储 —— 基础篇(马蜂窝)
- 使用触发器实现记录oracle用户登录失败信息到alert.log日志文件
- Java中使用Cookie记录用户访问次数
- 使用COOKIE对像实现保存用户基本信息(结合Session),ASP.Net实现用户登录全过程