[英]Codeigniter session problems
我已經在我的codeigniter應用程序中使用了很棒的codeigniter身份驗證庫ion auth創建了用戶身份驗證 ,身份驗證工作正常,但是當我注銷並單擊瀏覽器的后退按鈕時,我可以瀏覽我在應用程序中訪問過的所有頁面,引起關注的平均用戶隱私,但是如果我嘗試刷新頁面,它會識別出我已注銷。 當用戶單擊瀏覽器的后退按鈕時,如何強制瀏覽器重新加載? 關於如何解決此問題的任何建議將不勝感激。
編輯
控制器注銷功能
function logout() {
//log the user out
$logout = $this->ion_auth->logout();
//redirect them back to the page they came from
redirect('auth', 'refresh');
}
這是來自ion auth的注銷功能
public function logout() {
$this->ci->ion_auth_model->trigger_events('logout');
$identity = $this->ci->config->item('identity', 'ion_auth');
$this->ci->session->unset_userdata($identity);
$this->ci->session->unset_userdata('group');
$this->ci->session->unset_userdata('id');
$this->ci->session->unset_userdata('user_id');
//delete the remember me cookies if they exist
if (get_cookie('identity')) {
delete_cookie('identity');
}
if (get_cookie('remember_code')) {
delete_cookie('remember_code');
}
$this->ci->session->sess_destroy();
$this->set_message('logout_successful');
return TRUE;
}
我正在使用Codeigniter 2.0.3
Thanx提前..
實際上它們很可能已注銷(如您所說,刷新會使它們顯示為注銷)。 瀏覽器可能已經緩存了顯示的HTML,該HTML表明它們已登錄,但在注銷后不會重新加載它。
您可以通過設置Cache-Control
標頭將具有登錄相關信息的頁面設置為不緩存。
這可以用HTML來實現
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">
或PHP
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
您還可以使用以下代碼來實現對特定窗口的用戶歷史記錄的惡意刪除和不明智的清除。 這將需要作為注銷功能的一部分發送到瀏覽器,並且如果用戶禁用了javascript,則將無法使用。
<script language="javascript">
var Backlen=history.length;
history.go(-Backlen);
window.location.href=page url
</SCRIPT>
我強烈建議您禁用緩存,因為這會降低應用程序的速度。 由於存在愚蠢的編碼,我遇到了同樣的問題,我的工作是在控制器中進行的,我將以下代碼放在與數據庫交互的每個函數的頂部,供處於登錄狀態的用戶使用:
//Do not let anyone interact with database from cached pages!
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
}
因此,如果登錄用戶的瀏覽器被“備份”到緩存的登錄狀態並試圖擺弄數據庫,則會發生重定向到登錄頁面的情況,這也意味着刷新。
是的,ion auth存在此問題,我在應用程序中遇到了同樣的問題。 另一個問題是,如果會話在任何鏈接上到期,它將帶您進入登錄頁面。 但是,當您登錄並嘗試訪問會話已過期的最后一個鏈接時,它總是帶您返回登錄頁面。 要訪問該頁面,您需要清除瀏覽器緩存。 這是我在github上找到的解決方案關於ion auth的評論
function logout() {
//log the user out
$logout = $this->ion_auth->logout();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Wed, 4 Jul 2012 05:00:00 GMT"); // Date in the past
//redirect them back to the page they came from
redirect('auth', 'refresh');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.