1

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..

4 Answers 4

3

Try

session_start();
$_SESSION = array();
session_destroy();
Sign up to request clarification or add additional context in comments.

1 Comment

Tell us what happens. You logoff. Then how do you the session values are not destryed?
0

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

Comments

0

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

1 Comment

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

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

When 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.