在 PHP 中,可以使用以下两种方法来设置超时自动关闭页面:
使用header() 函数设置页面重定向:header("Refresh:5;url=closepage.php");以上代码将在当前页面打开 5 秒后,自动跳转到 closepage.php 页面。
window.location 方法进行页面重定向:echo "<script> setTimeout(function(){ window.location.href = 'closepage.php'; }, 5000); // 5 秒后自动跳转</script>";以上代码将在当前页面打开后的 5 秒后,自动跳转到 closepage.php 页面。
这两种方法都会在一定时间后自动关闭当前页面。


