为什么这次会议没有被破坏?

时间:2016-04-18 07:39:42

标签: php session

我使用这个 logout.php 页面从我的PHP项目中退出。

  "listeners": [{
    /**
     * rendered event
     * we'll use it to set up custom mouse events as well as
     * pre-zoom the chart
     */
    "event": "rendered",
    "method": function(e) {

      // add mouseup events
      e.chart.chartDiv.addEventListener("mouseup", handleEnd);
      e.chart.chartDiv.addEventListener("touchend", handleEnd);

      // function that handles pan end (mouse button released or touch ends)
      function handleEnd() {

        // check if there was an previous zoom event
        if (e.chart.lastZoomedEvent === undefined)
          return;

        // do what we need to do with it
        // ...
        console.log(e.chart.lastZoomedEvent);

        // reset 
        e.chart.lastZoomedEvent = undefined;
      }

      // pre-zoom the chart
      e.chart.zoomToIndexes(
        e.chart.dataProvider.length - 40,
        e.chart.dataProvider.length - 1);
    }
  }, {
    /**
     * zoomed event
     * we'll use it to track pan/zoom
     */
    "event": "zoomed",
    "method": function(e) {
      // log last zoomed event
      e.chart.lastZoomedEvent = e;
    }
  }]

[两者都在Firefox和Chrome中]:当我点击退出按钮时,页面会重定向到 login.php ,但是当我在不同的标签页中再次加载主页时(应该只在会话没有被破坏),它加载而不是重定向到login.php(这将是我的索引页)。

我不知道这段代码有什么问题。在session_unset()之前写session_destroy()会有什么不同吗?我该如何解决?

[仅限Chrome,在Firefox中没关系]:当我关闭Firefox时,会话会自动销毁,这很明显,但不适用于Chrome。 Chrome并没有摧毁它。怎么可能?我已彻底检查了我的代码,但我没有找到与Cookie相关的任何代码行。

另一个问题是,当我登录几分钟(我猜20-30)时,会话会自动销毁。有可能我为此错误地编写了一些代码吗?或者它是默认的吗?

2 个答案:

答案 0 :(得分:1)

不确定您是否使用cookie但我认为这将解决它 ....

$queryseenrun=mysqli_query($conn4, $queryseen);
session_unset();
    $_SESSION = array();
    // get session parameters 
    $params = session_get_cookie_params();
    //delete the actual cppkie
    setcookie(session_name(),'', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
    // Destroy session 
    session_destroy();
    //redirect to the index.php
    header("Location: login.php");
    exit();

答案 1 :(得分:1)

来自http://php.net/manual/en/function.session-unset.php

会话取消设置只是清除会话以供使用,但它不会被破坏,它仍然在用户的计算机上。

尝试以下方法:

session_start();  
session_destroy();  
$_SESSION = array();  
header('Location: index.php');