网站未使用cookie,在后台(iframe形式后台)登录后,如果点击“退出”可以完好的清除session,并返回到前台主页。但客户可能不会太在意这个问题,往往直接关闭浏览器了事。现在的问题是,也许客户打开了许多IE窗口,如果只关闭后台的窗口,不关别的,那么session是还在的,只有将全部窗口都X掉才会真正完全清除session我想让关闭后台浏览器窗口时也能清除session,该怎么做?谢谢回答
调试欢乐多
<head>
<script language="javascript">
window.onbeforeunload = function() {
return("Are You Sure?");//这里换成ajax请求,退出登录
}
</script>
<body>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function ajaxRequest(action){
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert("登出成功");
}
}
xmlhttp.open("POST", action, true);
xmlhttp.send();
}
</script>
</head>
<body onbeforeunload="ajaxRequest('logout.php')">
</body>
</html>
logut.php
<?php
session_start();
session_destroy();
?>
在IE与FireFox下表现很出色,但Opera和Safari则测试未通过。那个xmlhttp.readyState == 4 && xmlhttp.status == 200里面的4、200代表什么意思呢?非常感谢
欢迎访问 allniu.com 不错的PHP的网站,获取对你有所帮助
0:XMLHttpRequest对象还没有完成初始化。
1:XMLHttpRequest对象开始发送请求。
2:XMLHttpRequest对象的请求发送完成。
3:XMLHttpRequest对象开始读取服务器的响应。
4:XMLHttpRequest对象读取服务器响应结束。200 - OK 一切正常,对GET和POST请求的应答文档跟在后面。