一、登陆后台验证
1、登陆html配置提交地址:
<form action="{:U('Admin/Login/login')}" method="post" id="login">
2、Admin/LoginAction.class.php添加login()
Public function login() { if (!IS_POST) halt('页面不存在'); // echo $_SESSION['verify'] . '<br/>'; // echo md5($_POST['code']); // p($_POST); if (I('code', '', 'md5') != session('verify')) { $this->error('验证码错误'); } $username = I('username'); $pwd = I('password', '', 'md5'); $user = M('user')->where(array('username' => $username))->find(); if (!$user || $user['password'] != $pwd) { $this->error('账号或者密码错误'); } if ($user['lock']) $this->error('用户被锁定'); $data = array( 'id' => $user['id'], 'logintime' => time(), 'loginip' => get_client_ip() ); M('user')->save($data); session('uid', $user['id']); session('username', $user['username']); session('logintime', date('Y-m-d H:i:s'), $user['logintime']); session('loginip', $user['loginip']); $this->redirect('Admin/Index/index'); }
3、为了校验session信息判断登陆跳转
写一个CommonAction.class.php 重写 _initialize()方法
<?php Class CommonAction extends Action { Public function _initialize() { if (!isset($_SESSION['uid']) || !isset($_SESSION['username'])) {//如果没有检测到session中的uid或者username让他跳转到登陆页 $this->redirect('Admin/Login/index'); } } } ?>
4、IndexAction.class.php 继承CommonAction
这样首页跳转就会初始化判断是否通过登陆过来的而不是url跳转过来
5、写个退出方法在IndexAction.class.php
public function logout() { session_unset();//清除session session_destroy();//摧毁session $this->redirect('Admin/Login/index'); }
6、Index.html中
<a href="{:U('Admin/Index/logout')}" target="_self">退出</a>
详情请看源码
相关推荐
【标题】"PHP_THINKPHP_study10_建立后台项目与验证码的调用"涉及到的主要知识点是使用PHP的ThinkPHP框架构建后端项目,并且涵盖了验证码的生成与使用。ThinkPHP是一个基于MVC(Model-View-Controller)设计模式的...
《PHP_THINKPHP_study12_后台人员的管理和分页类的使用》 在PHP开发领域,ThinkPHP框架是一款广泛使用的MVC(Model-View-Controller)架构的PHP框架,它为开发者提供了强大的功能和高效的开发体验。这篇博客主要...
【标题】"PHP_THINKPHP_study14_RBAC" 是一个关于PHP编程语言与ThinkPHP框架的实战项目,特别关注于角色基础访问控制(Role-Based Access Control,简称RBAC)的实现。RBAC是一种常见的权限管理机制,它通过角色来...
#### 一、ThinkPHP简介与安装 - **ThinkPHP**是一款免费开源的,快速、简单的面向对象的轻量级PHP开发框架,它是为了敏捷开发和快速开发而设计的,其目标是实现简单、快速、优雅的PHP应用开发。 ##### 安装步骤: ...
通过PHP和ThinkPHP框架,后台可以实现这些功能的逻辑处理,如验证用户输入、处理预订请求、生成订单、处理支付等。MySQL数据库则存储用户信息、预订记录、场地状态等数据,保证数据的安全性和一致性。 在设计和实现...