tags:

views:

992

answers:

4

Hi friends i create a webpage in that i use session variables , when i click logout i clear the session variables using ajax , it working fine in IE , But when i use firefox sometimes the session is not destroyed , the code i used to clear session is [when i click logout button]

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");
}

else {

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

in logout.php file contain the folowing code

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

Please guide me to find the solution Thanks in advance..

+2  A: 

Try

session_start();
$_SESSION = array();
session_destroy();
Shoban
i tried friend , But still now i have the same problem .
Sakthivel
Tell us what happens. You logoff. Then how do you the session values are not destryed?
Shoban
A: 

session_destroy() alone is enough and is browser independent, as it happens on the server side.

vext01
ok , But still now the session variable is there when i use firefox . what can i do to destroy that session varable ?
Sakthivel
A: 

I had some sort of problem when

$_Session['session variable name'] was an array( 'first_element' => true, 'second_element' => '123456789' ).

When I did

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

then

session_destroy, and session_start and redefined $_Session['session variable name'] = array( 'first_element' => true );

Whan I was var_dumping $_Session['session variable name'],

was array( 'first_element' => true, 'second_element' => '123456789' ) with second_element!

I had to unset all elements in array.

This problem dissapeared when I upgraded php. Now I can't remember which php version I had.

fornve
A: 

Have you ever thought about browser caching? Even if you log out in firefox, firefox may still cache the logged in page.

try stopping page cache using something like this:

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