Welcome Guest, Not a member yet? Register   Sign In
Simple Acl
#4

(09-02-2017, 03:51 AM)pippuccio76 Wrote:
(09-02-2017, 03:45 AM)Paradinight Wrote:
(09-02-2017, 03:41 AM)pippuccio76 Wrote: hi , when an user log into my site a set 2 session variable :

 $_SESSION['user_id] and $_SESSION['role_id']

to redirect every view if the user aren't logged i try to insert an if in the construct :

Code:
   public function __construct() {
       
      parent::__construct();
     
      $this->load->library('session');
     
      $this->config->load('user_login');
     
      $this->load->model('user_model');

if(!isset($_SESSION['user_id'])){
             redirect('user/login');
         
}else{
             redirect('user/index');

      }


   }

But  the browser tell me that ther'are too many redirect . Why ?

you have a redirect loop. the __construct is in the user class?

edit: if you not loged in. the redirect looks like user/index to user/index to user/index

The construct is in User controller.

If i am not logged the variable $_SESSION['user_id'] not isset and i redirect to user/login

PHP Code:
if(!isset($_SESSION['user_id'])){
    
redirect('user/login');
 }else{
    
redirect('user/index');


the construct will be called automatically.

it check always the value and redirect you to the same constructor and it will redirect you.
Reply


Messages In This Thread
Simple Acl - by pippuccio76 - 09-02-2017, 03:41 AM
RE: Simple Acl - by Paradinight - 09-02-2017, 03:45 AM
RE: Simple Acl - by pippuccio76 - 09-02-2017, 03:51 AM
RE: Simple Acl - by Paradinight - 09-02-2017, 09:51 AM
RE: Simple Acl - by pippuccio76 - 09-03-2017, 01:32 AM
RE: Simple Acl - by InsiteFX - 09-03-2017, 03:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB