可以使用以下代码实现:

<?php
session_start();

// 设置访问有效期为60秒
$expire_time = 60;

// 检查是否有上次访问时间
if (isset($_SESSION['last_access_time'])) {
    $last_access_time = $_SESSION['last_access_time'];
    $current_time = time();
    $elapsed_time = $current_time - $last_access_time;
    
    // 如果访问时间超过了有效期,则跳转到其他页面
    if ($elapsed_time > $expire_time) {
        header('Location: other_page.php');
        exit();
    }
} else {
    $_SESSION['last_access_time'] = time();
}

以上代码中,使用了 $_SESSION 变量来保存上次访问时间,并通过 time() 函数获取当前时间。如果两者之差超过了有效期,则使用 header() 函数跳转到其他页面。注意要使用 exit() 函数来终止脚本运行,否则会继续执行下去

php 设置访问有效期60秒 过期跳转其他页面

原文地址: https://www.cveoy.top/t/topic/fDUg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录