zoukankan      html  css  js  c++  java
  • php后台如何避免用户直接进入方法实例

    这篇文章介绍了php后台如何避免用户直接进入方法实例,有需要的朋友可以参考一下

    1)创建BaseController控制器继承Controller(后台的一切操作要继承BaseController):

    在BaseController里面添加:

    public function checkLogin() { 
    
            if (Yii::app()->authority->isLogin() == Yii::app()->authority->getStatus('NOTLOGIN')) { 
                $url = $this->createUrl('user/login'); 
                if (Yii::app()->request->isPostRequest && Yii::app()->request->isAjaxRequest) { 
                    echo json_encode(array('code' => -101, 'message' => '用户未登录。', 'callback' => 'window.location="' . $url . '";')); 
                } else if (Yii::app()->request->isAjaxRequest) { 
                    echo '<script language="javascript">window.location="' . $url . '";</script>'; 
                } else { www.jbxue.com
                    $this->redirect($url); 
                } 
                exit; 
            } 
            return true; 
        }

     在components目录下创建Authority.php文件:

    <?php 
    /** 
     * 权限检查组件 
     */
    class Authority extends CComponent { 
        private $NOTLOGIN = -1; 
        private $FAILED = -2; 
        private $PASS = 1; 
    
        public function init() { 
    
        } 
    
        /** 
         * 检查是否登陆 
         * @return boolean  
         */
        function isLogin() { 
            return isset(Yii::app()->session['user']) ? $this->PASS : $this->NOTLOGIN; 
        } 
       
        /** 
         * 获取状态值 
         * @param string $name 
         * @return int  
         */ www.jbxue.com
        public function getStatus($name){ 
            return $this->$name; 
        } 
    } 
  • 相关阅读:
    if
    C#
    C#
    C#
    .net 5.0
    .net 5.0
    .net 5.0
    设计模式
    GAN网络中采用导向滤波的论文
    pytorch~多loss的选择
  • 原文地址:https://www.cnblogs.com/study100/p/3370347.html
Copyright © 2011-2022 走看看