Вопрос

Making an offline app with codeigniter . The app is used for storing client data . I have used codeigniter hmvc approach . and now i have about eight modules in my app like templates , search, client , user etc ..user module checks for admin authentication . The number of modules will increase in the future .

Now to check if a user is logged in as admin i have used this piece of code in every module in __construct() function without templates and user modules because when i try to put this code in templates or users controller then firefox says Page could not be redirected properly

if(!$this->session->userdata('user_type')){
    redirect(base_url().'users/login');
} 

Pasting this piece of code to templates and users module creates the problem . when i remove this code then everything works fine . as so user can still acess templates and user modules without login .

I just want to know that if there is any better way of doing it without pasting this piece of code in every controllers or making guest not to access any modules or method without login .

Это было полезно?

Решение

If you user HMVC than you can do it like this:

if(!$this->session->userdata('user_type')){
    redirect('module_name/users/login'); // change module_name with your module name
}

UPDATE: Maybe, You redirect on one page that redirect also... and put on loop

Другие советы

If you have specified the complete site url, into redirect there is already the path without using base_url()
try this:

if(!$this->session->userdata('user_type')){
    redirect('/users/login');
} 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top