破坏会话的麻烦

时间:2017-08-07 10:33:47

标签: php

我在用户注销帐户时遇到了破坏会话的问题。当我浏览任何限制用户不能在登录前访问的页面登出后我可以访问但是如果我在注销后关闭我的浏览器然后尝试访问该页面我不能。请解决我的问题,以便用户在注销后无法访问页面,即使他/她没有关闭浏览器。这是我的退出和销毁会话的代码。

     <?php
     // Initialize the session.
     // If you are using session_name("something"), don't forget it now!
      if(isset($_POST['logout'])){
      session_start();

      // Unset all of the session variables.
          $_SESSION = array();
          $_SESSION["Alogin"] = "";

      // 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();
      }
     ?>

2 个答案:

答案 0 :(得分:0)

  1. 将您的session_start ();放在if语句和
  2. 之外
  3. 如果您发送print_r ($_POST);
  4. ,请与$_POST['logout']核对

答案 1 :(得分:0)

会话var firstDate = new Date(2006,05,09); var secondDate = new Date(1990,01,01); function (firstDate, secondDate){ var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay))); return diffDays; } 必须位于顶部

session_start()