2017-09-07 4 views
0

私はホームページ用のヘッダファイルとそのヘッダにログインページ を持っています。codeigniterセッション:php

+0

https://www.codeigniter.com/user_guide/general/controllers.html#class-constructorsコントローラの__construct()部分のコード – user4419336

+0

もう一度ログインページにあるリダイレクトを削除してください。既にログインしていますなぜあなたはログインにリダイレクトしていますか? – Nobita

答えて

1

削除..私はそれ

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

の上にこのコードを書いたが、それは同じページに私をリダイレクトし続け、それが

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

は上記のコードを試してみてください何も示していませんログインページ、既にログインページにリダイレクトする

if ($this->session->userdata('logged_in')==true){ 
    redirect('home'); 
} 
ログインを除いて0

、あなたはページをリダイレクトすることができます:)

ログインページとホームページを異ならせるだけで

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

とヘッダー内の

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

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

    redirect('home','refresh'); 

} 
1

この は、これらのラインを入れて試してみてくださいを送りますすべてのコントローラの__construct機能

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