防止地址栏的跳转

PHP页面:

<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Commen extends Controller
{
//初始化
public function _initialize()
{
//判断session的值
if(!Session::get("user",'think'))
{
$this->error("非法登录");
}
$this->power_cat();
}
//查看权限
public function power_cat()
{
$request=Request::instance();
$controller=$request->controller();//当前控制器
$action=$request->action();//当前方法名
$data=Session::get("data",'think');
$falg=false;
foreach ($data as $k=>$v)
{
if($v['action_name']==$action)
{
$falg=true;
}
}
if(!$falg)
{
$this->error("对不起,您没有权限");
}
}
}
posted @ 2018-10-15 10:11  PHP小媛  阅读(978)  评论(0编辑  收藏  举报