即使在IE 8和9中注销后,php会话也没有被破坏

时间:2012-09-14 07:09:20

标签: php internet-explorer session logout

我试图找出下面的代码有什么问题,每当我尝试使用Internet Explorer注销时,我都无法做到这一点,它只会在几次重新加载后或关闭浏览器后注销。

 <?php
//Start session 
session_start();
require("../../class-settings.php");
function write_at_sess_destroy(){
    $time=date('h:i:s A',time());
    $sql="update " . DB_PRE."user_master set `guid` = '',`user_first_login`='0' WHERE user_id ='".  $_SESSION['user']."'";
    $sql_log= "update " . DB_PRE."user_log set logout_time='$time' where user_id='{$_SESSION['user']}' and logger_id='{$_SESSION['DYNAMIC_LOGGER_ID']}'";       
    if(mysql_query($sql))if(mysql_query($sql_log)) return true;
}
if(write_at_sess_destroy()){
    function unset_sessions(){
        session_start();
        if($_SESSION['adminlang'])unset($_SESSION['adminlang']);
        unset($_SESSION['loginID']);
        unset($_SESSION['utype']);
        return true;
    }
    if(session_destroy()){
        header("Location:../../../");
        exit;
    }
    else{
        echo "error...";    
    }
}
?>

1 个答案:

答案 0 :(得分:0)

为什么不能简化:

<?php
    session_start();
    require("../../class-settings.php");
    function write_at_sess_destroy(){
        $time=date('h:i:s A',time());
        $sql = "update " . DB_PRE."user_master set `guid` = '',`user_first_login`='0' WHERE user_id ='".  $_SESSION['user']."'";
        $sql_log = "update " . DB_PRE."user_log set logout_time='$time' where user_id='{$_SESSION['user']}' and logger_id='{$_SESSION['DYNAMIC_LOGGER_ID']}'";       
        if(mysql_query($sql))if(mysql_query($sql_log)) return true;
    }
    if(write_at_sess_destroy()){
        session_regenerate_id();
        session_destroy();
        $_SESSION = array();
        header("Location: ../../../");
        exit;
    } else {
        echo mysql_errno() . ": " . mysql_error() . "\n";
    }
?>