简体   繁体   中英

codeigniter session : php

I have one header file for the home page and the login page in that header. I wrote this code on top of it

<?php
if ($this->session->userdata('logged_in')==true ){
  redirect('home','refresh');
}else{
  redirect('home/login','refresh');
}
?>

but it keeps redirecting me to the same page and it shows nothing

<?php
 if ($this->session->userdata('logged_in')!==FALSE){  
    redirect('home','refresh');
 }
  else{
   redirect('home/login','refresh');
 } 
?>

try the above code..

$user_logged_in=$this->session->userdata('logged_in');

if (!$user_logged_in)
{
  redirect('home/login','refresh');
}else{

    redirect('home','refresh');

}

Remove the else redirect on login page, its already in login page

if ($this->session->userdata('logged_in')==true ){
  redirect('home');
}

except login, you can redirect the page :)

to differ the login page and home page just send the

$this->data["pagename"]="login"; in login function and
$this->data["pagename"]="home"; in home function 

and in header

if ($this->session->userdata('logged_in')==true ){
      redirect('home');
    } else { 
      if($pagename!="login")
       {
          redirect('home/login');
       }
    }

Try this put these line in every controller's __construct function

    if ($this->session->userdata('logged_in') !=true) {
      if ($this->router->fetch_class() != 'home' && $this->router->fetch_method() != "login") {
        redirect("home/login");
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM