咯卡 发表于 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());               
          }         
       }      
}


是什么意思呢我在别人的代码里找到的想做一个全局检查是否登录的功能

Hex 发表于 2017-2-25 22:05:07

咯卡 发表于 2017-2-25 11:01
function checkLogin(){               $ci =& get_instance();      
         $ci->load->helper('ur ...

我感觉没什么特别的意思吧,就是检查是否已经登录,没登录就跳转。

longjianghu 发表于 2017-2-26 10:41:18

搞这么复杂直接判断session是否存在,不存在就跳转:lol
页: [1]
查看完整版本: 求大神们帮我看下这段代码