php - post_controller_constructor Hooks redirection isseus in CodeIgniter -


hello can 1 me solve out redirect issues in codeigniter. create hook login authentication .

below hook

<?php  if ( ! defined('basepath')) exit('no direct script access allowed');  class login_auth {      function __construct() {         $this->ci = &get_instance();          if (!class_exists('session'))         {             $this->ci->load->library('session');         }                 }      function auth(){                                            if(! $this->ci->session->userdata('islogin')         {             redirect(base_url().'loginctrl/index');         }     } 

the purpose create hook when try enter url when not logged in should redirect login page

but shows webpage has redirect loop

it have redirect loop it's checking every page session. including login page.

you this;

if(!$this->ci->session->userdata('islogin')) {     // not logged in. trying login?     if(!in_array($this->ci->uri->uri_string(), array('login', 'forgot-password')))     {         redirect('login');     } } 

this check if user logged in. if not, check current uri_string , compare array of "allowed" uri's array('login', 'forgot-password')

hope helps.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -