我想检查自会话开始以来经过了多长时间,并与INT中的数据库列值进行比较,看看它是否已过期并注销用户。 在非活动地点= 10;在我的下面的代码中,我想在INT
中传递db列值<?php require_once('Connections/noundb.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
$inactive = 10; // Set timeout period in seconds
if (isset($_SESSION['timeout'])) {
$session_life = time() - $_SESSION['timeout'];
if ($session_life > $inactive) {
session_destroy();
header("Location: l.php");
}
}
$_SESSION['timeout'] = time();
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "l.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
答案 0 :(得分:1)
我建议您在需要一次之前进行会话启动,并且不要关闭并打开php标签:这意味着要发送给客户端的输出,然后没有&#34;托管&#34;会话可以开始。
试试这个:
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
require_once('Connections/noundb.php');
// [other code ]