且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 会话超时

更新时间:2023-12-04 19:34:52

首先,存储用户上次提出请求的时间

first, store the last time the user made a request

<?php
  $_SESSION['timeout'] = time();
?>

在随后的请求中,检查他们在多久之前提出了上一个请求(在此示例中为 10 分钟)

in subsequent request, check how long ago they made their previous request (10 minutes in this example)

<?php
  if ($_SESSION['timeout'] + 10 * 60 < time()) {
     // session timed out
  } else {
     // session ok
  }
?>