跟着百度学PHP[14]-COOKIE的应用/网站登陆案例完整案例
2017-02-24 02:17
615 查看
先在数据库当中创建以下数据:
allow_x中的一代表用户的权限,其值中的 1代表拥有权限,0代表没有权限。看一下结构。
然后我们写几个文件夹:
Index.php 首页
Cookie.php Cookie页面
Content.php 文章页面
Exit.php 离开页面
第一个Index.php
Exit.php
mysql> create table user( -> id int not null auto_increment, -> username varchar(50) not null default '', -> password char(32) not null default '', -> email varchar(80) not null default '', -> allow_1 smallint not null default 0, -> allow_2 smallint not null default 0, -> allow_3 smallint not null default 0, -> primary key(id)); mysql> insert into user(username,password,email,allow_1,allow_2,allow_3) values('admin',md5('admin'),'admin@admin.com',1,1,1); Query OK, 1 row affected (0.18 sec) mysql> insert into user(username,password,email,allow_1,allow_2,allow_3) values('shuaige',md5('shuaige'),'shuai@admin.com',0,1,1); Query OK, 1 row affected (0.12 sec) mysql> insert into user(username,password,email,allow_1,allow_2,allow_3) values('daniu',md5('daniu'),'daniu@admin.com',0,0,1); Query OK, 1 row affected (0.14 sec)
allow_x中的一代表用户的权限,其值中的 1代表拥有权限,0代表没有权限。看一下结构。
mysql> select * from user; +----+----------+----------------------------------+-----------------+---------+---------+---------+ | id | username | password | email | allow_1 | allow_2 | allow_3 | +----+----------+----------------------------------+-----------------+---------+---------+---------+ | 1 | admin | 21232f297a57a5a743894a0e4a801fc3 | admin@admin.com | 1 | 1 | 1 | | 2 | shuaige | 37d2b9990df5a6843caf19352fee42a6 | shuai@admin.com | 0 | 1 | 1 | | 3 | daniu | 76720c5adee75ce9c7779500893fb648 | daniu@admin.com | 0 | 0 | 1 | +----+----------+----------------------------------+-----------------+---------+---------+---------+ 3 rows in set (0.00 sec)
然后我们写几个文件夹:
Index.php 首页
Cookie.php Cookie页面
Content.php 文章页面
Exit.php 离开页面
第一个Index.php
<?php if (isset($_COOKIE["username"])) {//问以下是否设置了username setcookie("id","",time()-3600,"/"); setcookie("username","",time()-3600,"/"); setcookie("password","",time()-3600,"/"); setcookie("allow_1","",time()-3600,"/"); setcookie("allow_2","",time()-3600,"/"); setcookie("allow_3","",time()-3600,"/"); echo "再见,亲爱的{$_COOKIE['username']}"; } ?> <script> setTimeout("location='index.php'",3000); </script>
Exit.php
相关文章推荐
- 跟着百度学PHP[15]-SESSION的应用/网站登陆案例完整案例
- 跟着百度学PHP[10]-读取COOKIE案例
- PHP绿色集成环境在云服务器上的应用,PHPWAMP在服务器上搭建网站案例
- 跟着百度学PHP[14]-PDO-优化驱动
- 跟着百度学PHP[7]会话控制(session与cookie) 1.cookie的设置
- 【过滤器】(3)过滤器的应用案例:网站自动登录技术(Cookie记忆)
- 跟着百度学PHP[14]-PDO之Mysql的事务处理1
- 跟着百度学PHP[4]OOP面对对象编程-14-克隆对象__clone()方法
- 跟着百度学PHP[14]-初识PDO数据库抽象层
- 跟着百度学PHP[14]-PDO的预处理语句1
- 跟着百度学PHP[14]-PDO的预处理语句2
- 跟着百度学PHP[14]-PDO之Mysql的事务处理2
- 跟着百度学PHP[14]-PDO的错误处理模式&PDO执行SQL
- 跟着百度学PHP[9]-session与cookie的异同
- PHP绿色集成环境在云服务器上的应用,PHPWAMP在服务器上搭建网站案例
- php网站制作(5)-类似于百度优酷等一样弹出的登陆框
- 跟着百度学PHP[17]-PHP扩展CURL的模拟登陆并获取数据
- PHP版本--HTTP session cookie原理及应用
- php登录完整代码cookie版本
- PHP session的实现原理 大网站应用应注意的问题