问题描述
我要实现和登录验证功能,当控制器加载时检查每个URL,如下所示?
I want to implement and login authentication function that check every URL when a controller is loaded like this ?
//get the current URL
$url = $this->uri->uri_string();
if( ($this->ion_auth->logged_in()== false )&&
!( in_array($url,$public_allowed_urls) ) ) {
redirect('users/login');
}
我也尝试过从 code>
$ config ['uri_protocol'] ='REQUEST_URI';
I have also tried changing this from AUTO
$config['uri_protocol'] = 'REQUEST_URI';
请你怎么做.. ..使用最新的CI? / p>
Please how do you do it ..i use latest CI ?
推荐答案
您知道什么..您将花费时间寻找URI_STRING THING的工作吗?
You know what ..you will spend your time looking to make work for URI_STRING THING?
但是,我已经为你的人们做了一个解决方案...
But , i have made a solution to you folks ...
获取动作和控制器
像Weclome / Home,users / login,sell / sell,sell / index,sell /','/'
//get the current URL
$controller= $this->uri->segment(1); // controller
$action = $this->uri->segment(2); // action
$url = $controller . '/' . $action;
//'this returns / sometimes and also like sell/ returned'
if( ($this->ion_auth->logged_in()== false )&& (in_array($url,$public_allowed_urls) ) )
{
redirect('users/login');
}
done men!
已编辑:
$ this-> uri-> segment(1);
不能是控制器名称所有时间。获取控制器名称使用 $ this-> router-> class
和方法 $ this-> router->
$this->uri->segment(1);
cannot be controller name all time.To get controller name use $this->router->class
and for method $this->router->method
这篇关于如何使用uri_string()codeigniter获取一个URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!