用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1336|回复: 3
收起左侧

[讨论/交流] 求大神们帮我看下这段代码

[复制链接]
发表于 2017-2-25 11:01:02 | 显示全部楼层 |阅读模式
function checkLogin(){
   $ci =& get_instance();
   $ci->load->helper('url');
   $d = trim($ci->router->fetch_directory().'/');
   $c = $ci->router->fetch_class();
   $m = $ci->router->fetch_method();
   $username = $ci->session->userdata('username');
   if ($d = 'admin' && $c = 'Index' && $m !='login'){
      if (empty($username)){
         redirect('admin/Index/login?back_url='.uri_string());
      }
   }

}


 楼主| 发表于 2017-2-25 11:01:17 | 显示全部楼层
本帖最后由 咯卡 于 2017-2-25 11:02 编辑

function checkLogin(){                 $ci =& get_instance();        
         $ci->load->helper('url');               
         $d = trim($ci->router->fetch_directory().'/');     
         $c = $ci->router->fetch_class();            
        $m = $ci->router->fetch_method();              
       $username = $ci->session->userdata('username');               
     if ($d = 'admin' && $c = 'Index' && $m !='login'){                    
          if (empty($username)){                             
               redirect('admin/Index/login?back_url='.uri_string());               
          }         
       }        
  }


是什么意思呢  我在别人的代码里找到的  想做一个全局检查是否登录的功能  
发表于 2017-2-25 22:05:07 | 显示全部楼层
咯卡 发表于 2017-2-25 11:01
function checkLogin(){                 $ci =& get_instance();        
         $ci->load->helper('ur ...

我感觉没什么特别的意思吧,就是检查是否已经登录,没登录就跳转。
发表于 2017-2-26 10:41:18 | 显示全部楼层
搞这么复杂直接判断session是否存在,不存在就跳转

本版积分规则