My controller
class Backspaze extends CI_Controller
{
function __construct()
{
parent::__construct();
session_start();
$this->load->library('session');
$this->load->model('getDB');
$this->IsLogged();
}
function IsLogged()
{
if (!$this->session->userdata('id'))
{
header('Location: '.base_url().'login');
}
}
function Login()
{
$this->load->view('Auth/Login');
}
}
.htaccess
RewriteBase /backspaze
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I almost tried all things which is available in internet the page gets redirect loop while checking for user is logged in, please give me some solutions
MY Config $config['uri_protocol'] = 'AUTO';
Please check the following points
In your case, You should not check the session in
constructor
level. , Means, your controller consists of public & authenticated pages. So it will be looping/redirecting inside this controller only.Move the session checking condition to the specific page and redirect to
login
page if suppose no session for authenticated pages. Below I have checked foruser_details
page which is I created for your understanding.In your login method, you should check the
already logged in or not
and if yes, it should be go todashboard
page. I have created one method for thatIsAlreadyLogged
. please check it.Don't add
session_start()
in your controller which will be take care of CI coreUse build-in
redirect
method which is CI core hasYou should check session in constructor level if all pages are need to be authenticated in controller.
.
remove the line
codeigniter handle it itself.
Replace this
with
but make sure you have loaded url helper