douzhongpi9734
douzhongpi9734
2017-06-12 08:26

几分钟后PHP会话超时

  • session
  • php

good morning, I am trying to create a session that times out after some minutes, I tried out the code below but it just destroys the session when I refresh the page

<?php
    //start session
    session_start();

    //database connection
    include('database/connection.php');

    //site config
    $site_name = "Lilaga";

    //session expiration timer
    $expireAfter = 1;

    if(isset($_SESSION['phone'])){
        $sql = mysqli_query($connection, "SELECT * FROM customer WHERE phone =$_SESSION[phone]");
        $row = mysqli_fetch_array($sql);
        $name = $row['firstname'] ." ". ucfirst($row['lastname']);
        $phone = $row['phone'];
        $email = $row['email'];
        $customerID = $row['customerID'];

        $secondsInactive = time() - $_SESSION['phone'];
        $expireAfterSeconds = $expireAfter * 60;
        if($secondsInactive >= $expireAfterSeconds){
            session_unset();
            session_destroy();
        }
    }
?>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐