//获取当前登录
function loginEmployeeid() {
$employee = session('employee');
//$class = new \Org\Util\Session();
//$employee = $class->get("employee");
if (empty($employee)) {
return 0;
} else {
$last_access=session('last_access');
if($last_access!=null&&(time()-$last_access)<=10){
session('last_access', time());
return 1;
}else{
return 0;
}
}
}<?php
namespace Home\Controller;
use Think\Controller;
class AdminController extends Controller {
protected function _initialize(){
if (!loginEmployeeid()) {
//操作方法
$actionName = strtolower(ACTION_NAME);
//操作控制器
$controllerName = strtolower(CONTROLLER_NAME);
if(!in_array($actionName, array("login","loginhandle"))&&!in_array($controllerName, array("index"))) {
$this->redirect('Home/Index/login');
exit;
}
}
}
}<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends AdminController {
//首页
public function index() {
$this->display();
}
//登录界面
public function login() {
$this->display();
}
//退出系统处理
public function outHandle(){
session(null);
$msg['msg'] = "success";
$this->ajaxReturn($msg,"JSON");
}
//登录系统处理
public function loginHandle(){
session("employee",time());
session('last_access',time());
$msg['msg'] = "success";
$this->ajaxReturn($msg,"JSON");
}
public function A(){
$this->display();
}
public function B(){
$this->display();
}
}<?php
return array(
'SESSION_OPTIONS' => array(
'name' => 'employee', //设置session名
'expire' => 10, //秒
'use_trans_sid' => 1, //跨页传递
'use_only_cookies' => 0, //是否只开启基于cookies的session的会话方式
),
'DEFAULT_MODULE' => 'Home', // 默认模块
'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称
'DEFAULT_ACTION' => 'index', // 默认操作名称
//数据库配置信息
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'gd', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => 'root', // 密码
'DB_PORT' => 3306, // 端口
'DB_PREFIX' => 'think_', // 数据库表前缀
);
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。