一、登陆后台验证
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>
详情请看源码
相关推荐
NULL 博文链接:https://hefengjun1.iteye.com/blog/2333706
thinkphp问卷_问卷mvc_thinkphp_thinkphp问卷_问卷_thinkphp系统_源码.zip
thinkphp_thinkphp_thinkphp5_源码.zip
功能强大的后台管理集成代码、thinkphp、phpcmf
ThinkPHP5.0.5完整版_ThinkPHP_full_v5.0.5 欢迎关注PHP学习博客:http://blog.csdn.net/column/details/14209.html
ThinkPHP-2.0-API的chm文件
tp5开发的通用后台模板,权限管理+文章管理+幻灯片
thinkphp开发模板,把常用的功能都写好了,可以直接使用
NULL 博文链接:https://hefengjun1.iteye.com/blog/2334641
ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,遵循Apache2开源协议发布
NULL 博文链接:https://hefengjun1.iteye.com/blog/2335818
课件管理系统,主要是用于老师的课件上传,课件基本管理等等
使用ThinkPHP,你可以更方便和快捷的开发和部署应用
深入浅出PHP框架Thinkphp实战开发_thinkphp基础项目实战11.pptx
NULL 博文链接:https://hefengjun1.iteye.com/blog/2334651
ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,遵循Apache2开源协议发布,是为了敏捷WEB应用 开发和简化企业级应用开发而诞生的。拥有众多的优秀功能和特性,经历了三年多发展的同时,在社区...
前端采用小程序,后台使用的是ThinkPhp5.0;支持多平台音乐解析
thinkphp Excel 插件请自行安装