2009-06-01 87 views
0

我創建一個網頁,我使用會話變量,當我點擊註銷我清除會話變量使用Ajax,它在IE中工作正常,但是當我使用Firefox有時會話不會被銷燬,代碼我用於清除會話是[當我點擊註銷按鈕]刪除會話變量在PHP

function floadhomepage(){

ajaxFunction(); 
//alert('Logout clicked'); 
window.location.replace("index.php"); 

}

function ajaxFunction() 
var xmlhttp; 
if (window.XMLHttpRequest){ 
    // code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 


else if (window.ActiveXObject){ 
// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 

否則{

alert("Your browser does not support XMLHTTP!"); 
} 
xmlhttp.onreadystatechange=function(){ 
} 
xmlhttp.open("GET","logout.php",true); 
xmlhttp.send(null); 
} 
在logout.php文件

包含如下因素代碼

<?php 
session_start(); 
session_destroy(); 
unset($_Session['session variable name']); 
?> 

請指引我找到解決辦法提前 謝謝..

回答

2

嘗試

session_start(); 
$_SESSION = array(); 
session_destroy(); 
+0

我試過的朋友,但現在還在我有同樣的問題。 – Sakthivel 2009-06-01 07:00:26

+0

告訴我們發生了什麼。你註銷。那麼你怎麼會議價值沒有destryed? – Shoban 2009-06-01 07:01:27

0

session_destroy()獨是足夠的,並且是獨立於瀏覽器的,因爲它發生在服務器端。

0

我有某種問題時

$_Session['session variable name']是一個array('first_element' => true, 'second_element' => '123456789')

當我做

unset($_Session['session variable name'])

然後

session_destroy,並session_start 並重新定義$_Session['session variable name'] = array('first_element' => true);

當我var_dumping $_Session['session variable name']

array('first_element' => true, 'second_element' => '123456789')無線th second_element!我不得不取消數組中的所有元素。

當我升級php時,這個問題消失了。現在我不記得我有哪個PHP版本了。

0

你有沒有想過瀏覽器緩存?即使您使用Firefox註銷,Firefox仍可能會緩存已登錄的頁面。使用這樣的事情

嘗試停止頁面緩存:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past