【问题标题】:Destroying session in php is SLOW working在 php 中销毁会话工作缓慢
【发布时间】:2017-01-14 02:15:38
【问题描述】:

我在 survey.php 文件的开头写了这段代码:

<?php 
    //Check if session set 
    if (session_status() == PHP_SESSION_NONE)
        session_start();

    //Check if un user login or no
    if (isset($_SESSION['user'])){
        //check if the user is admin
        if($_SESSION['type']==1)
            header( 'Location: admin.php');
    }
    // check if no user login
    else
        //Go to first page
        header( 'Location: index.php');

    //Check if thimeout is finished.
    if( $_SESSION['last_activity'] < time()-$_SESSION['expire_time'] ) { 
        session_unset();
        session_destroy();
        //Go to first page
        header('Location: index.php'); 
    } 
    else{ 
        $_SESSION['last_activity'] = time();
    }
?>

我把 cmets 放在里面了。

在完成进入 index.php 页面的超时后,网站变得非常缓慢,然后进入 index.php

但如果我通过 google chrome 清理 cookie,它会变得像以前一样快。

【问题讨论】:

    标签: php google-chrome session timeout


    【解决方案1】:

    我自己解决了,

    我不喜欢我使用的方法,但它有效。

    如果有人有任何建议,我会很高兴。

    那是因为header('Location: index.php');

    我写

    if( $_SESSION['last_activity'] < time()-$_SESSION['expire_time'] ) { 
        session_unset();
        session_destroy();
        //header('Location: index.php'); 
        echo "Session expired click <a href=\"index.php\">here</a> for going in login page.";
        exit(0);
    
        //Go to first page
    } 
    

    【讨论】:

      猜你喜欢
      • 2018-12-24
      • 2012-05-25
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 2011-10-09
      • 2014-02-09
      相关资源
      最近更新 更多