我有这个功能来跟踪用户 session 时间。
function sessionTracker(){
ini_set('session.cookie_lifetime', 86400);
ini_set('session.gc_maxlifetime', 86400);
$sid = session_id();
if ($sid != '') {
//echo "Session exists!";
} else {
//echo "No current session exists! Starting...";
session_start();
}
if(!isset($_SESSION['username']))
{
header("location:login.php");
exit();
}
但是当它到达 session_start() 时,我收到“超过 30 秒的最大执行时间”;线。有没有更好的功能或者我该如何解决这个问题?我不是一直都明白,但它总是那一行。
function sessionReup() {
$time = $_SERVER['REQUEST_TIME'];
//for a 30 minute timeout, specified in seconds
$timeout_duration = 1800;
/*
Here we look for the user’s LAST_ACTIVITY timestamp. If
it’s set and indicates our $timeout_duration has passed,
blow away any previous $_SESSION data and start a new one.
*/
if (isset($_SESSION['LAST_ACTIVITY']) && ($time - $_SESSION['LAST_ACTIVITY']) > $timeout_duration) {
session_unset();
session_destroy();
session_start();
header("location:login.php");
exit();
}
/*
Finally, update LAST_ACTIVITY so that our timeout
is based on it and not the user’s login time.
*/
$_SESSION['LAST_ACTIVITY'] = $time;
}
最佳答案
代码没有显示一行,这可能是运行时间较长的原因。 session 存储在硬盘上。该设备真的很慢吗? 您是否交换了 session 处理程序?
但是您可以将代码简化为:
session_start();
if(!isset($_SESSION['username']))
{
header("location:login.php");
exit();
}
关于php - session_start() 上的 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31052064/