PHP:“您必须遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他有关法律法规。”;该网站有太多的重定向;当使用php会话时
在我的页面中使用此代码时出现问题: 带有过期会话的代码PHP:“您必须遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他有关法律法规。”;该网站有太多的重定向;当使用php会话时,php,session,timeout,Php,Session,Timeout,在我的页面中使用此代码时出现问题: 带有过期会话的代码 <?php session_start(); if(!isset($_SESSION['clientmacs']) ) { header('Location: index.php'); } else { if(time() - $_SESSION['timeLogin'] > 1800) { header('Location: include/logout.php'); } $
<?php
session_start();
if(!isset($_SESSION['clientmacs']) ) {
header('Location: index.php');
} else {
if(time() - $_SESSION['timeLogin'] > 1800) {
header('Location: include/logout.php');
}
$userclient = $_SESSION['clientmacs'];
?>
<html>
HTML CODE
</html>
<?php
}
?>
<?php
session_start();
if(!isset($_SESSION['clientmacs'])) {
header('Location: index.php');
} else {
$userclient = $_SESSION['client'];;
?>
<html>
HTML CODE
</html>
<?php
}
?>
以下是您需要添加的内容
if(!isset($_SESSION['clientmacs'])) {
$_SESSION['clientmacs'] = 'something' // or it will redirect forever;
header('Location: index.php');
}
您的注销将重定向到您的索引,在那里它将再次检查条件
if(time()-$\u会话['timeLogin']>1800)
这将是真实的,并将其发送回注销,等等。您需要更改yoiur$\u会话['timeLogin'],否则您将永远无法打破此循环。执行重定向时,您需要重置超时($\u会话['timeLogin'])的$\u会话值,否则当客户端从重定向返回时,会话中的值相同,将再次重定向 您可以通过以下方式解决此问题:
if(!isset($_SESSION['clientmacs']) ) {
$_SESSION['clientmacs'] = ""; // add this line if not added somewhere else
header('Location: index.php');
}
及
也许(取决于您的逻辑)最好清除整个会话,并在执行重定向时通过正常流(
session\u destroy()
)对其进行重新配置。尝试在IF语句之外计算时差
e、 g
在其他php文件中添加的会话名称@SoldierCorp你必须仔细检查,因为这就是导致你无限重定向对我和@Francisco Spaeth也有效的原因/适合我和@Ibu回答!
if(!isset($_SESSION['clientmacs']) ) {
$_SESSION['clientmacs'] = ""; // add this line if not added somewhere else
header('Location: index.php');
}
if(time() - $_SESSION['timeLogin'] > 1800) {
$_SESSION['timeLogin'] = time(); // add this line
header('Location: include/logout.php');
}
$difference = time() - $_SESSION['timeLogin'];
if($difference > 1800){
//Do Something
}