dongyan3237 2013-01-28 20:51
浏览 24
已采纳

print仍会在destroy之后写入旧的Session变量值

I use some Session variables. When i logout, function show_number should write 0 number but it doesnt.

logout.php:

<?php
session_start();
session_destroy();
require_once('upper.php');
show_number(); //this function is declared on upper.php
?>

index.php:

<?php
$_SESSION['var'] = 1;
echo "<a href="logout.php">Logout</a>
?>

upper.php:

function show_number() { // shows value of $_SESSION['var'];
if (isset($_SESSION['var']))
  echo "1";
else
  echo "0";
}

And the problem is: When I click Logout link echo still writes number 1 and i have to reload page to see 0 value.

Cheers

  • 写回答

1条回答 默认 最新

  • dongtui8593 2013-01-28 20:53
    关注

    The global $_SESSION object will not be cleared by session_destroy:

    It does not unset any of the global variables associated with the session, or unset the session cookie.

    To clear the session data in your code:

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

    Or to more thoroughly eradicate all session data (from the same documentation page):

    <?php
    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();
    
    // Unset all of the session variables.
    $_SESSION = array();
    
    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 42000,
            $params["path"], $params["domain"],
            $params["secure"], $params["httponly"]
        );
    }
    
    // Finally, destroy the session.
    session_destroy();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。