2013-08-24 46 views
4

我想在codeigniter framework.my中設計一個登錄/註銷頁面。我的問題是,當我註銷web頁面時,我正在重定向到登錄頁面。 當我回去我得到一個網頁,其中說:在codeigniter中註銷

文件過期

This document is no longer available. 

但是,當我刷新此頁面我收到登錄到系統再次(OO)

以下代碼包含我的構造函數和註銷功能。請幫我設計一個完美的登錄註銷頁面

function __construct() 
{ 
    parent::__construct(); 

    $this->load->model('user_model');  

    $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); 
     $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); 
     $this->output->set_header('Pragma: no-cache'); 
     $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
} 

function logout() 
{ 
    $newdata = array(
       'user_name' =>'', 
       'user_email' => '', 
       'logged_in' => FALSE, 
       ); 

    $this->session->unset_userdata($newdata); 
    $this->session->sess_destroy(); 

    redirect('default_controller','refresh'); 
} 

我試過找到正確的註銷方法,但我無法做到。

+0

嗯,你可以上傳你的登錄方法藏漢並給你的具體交互步驟一些細節(即表單提交 - >登錄頁(重定向? ) - >註銷(重定向) - >歷史後退 - >刷新)?所以基本上我很好奇你是否可能通過刷新來重複登錄過程,在這種情況下,登錄後的重定向應該有所幫助。 – Filou

+1

aahh,你在加載會話庫嗎?任何這樣的錯誤可能因爲重定向而被隱藏。 – Filou

+0

我是自動加載會話庫 –

回答

15

儘量簡單地這樣

function logout() 
{ 
    $user_data = $this->session->all_userdata(); 
     foreach ($user_data as $key => $value) { 
      if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') { 
       $this->session->unset_userdata($key); 
      } 
     } 
    $this->session->sess_destroy(); 
    redirect('default_controller'); 
} 
1

不需要使用這條線

$ this-> session-> sess_destroy();

+6

其實,這是* only *行需要... – Shomz

+0

我沒有得到你..我仍然面臨着與mylogout的問題 –

0
public function Logout() 
    { 
     $this->session->sess_destroy(); 
     redirect('login'); 
    } 
/** Here ('login') is controller class . 
In view ('logout-page'):-**/ 

<a href="home/logout">Logout</a> 
+0

需要一些格式和一些解釋。 –