简体   繁体   English

codeigniter会话:PHP

[英]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 删除登录页面上的else重定向,它已经在登录页面中

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 尝试将这些行放入每个控制器的__construct函数中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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