我有一个php页面(index.php),在验证用户名和密码之后会设置一个会话($ _ SESSION ['expire']),该会话将在30分钟后(30分钟后)过期并取消设置登录按钮)并将我们再次重定向到index.php:
header('location:index.php');
验证后,将在索引页面中显示一个菜单,其中一个项目是ContentManager.php。 如下图所示,单击此项我们将连接到db并将输入contentmanager.php
switch($_REQUEST['action'])
{
case 'ContentManager' :
include('model/content.php');
$contents = getContent($conn);
include('view/contentmanager.php');
break;
}
在ContentManger.php中我有:
<?php
//if the session is not unset and expired yet
if ( isset($_SESSION['expire']) && ($now<= $_SESSION['expire']))
{
?>
do sth...
<?php
}
else
{
//unset the session and redirect to index.php again
unset($_SESSION['expire']);
session_destroy();
header('location:../index.php');}
?>
这很好用,但问题是在经过30分钟后我必须按“ContentManager”2次才能重定向到index.php 如果我只按一次显示空白页面。但是,通过第二次刷新页面,它将再次重定向到登录页面(index.php)。
请帮帮我......
答案 0 :(得分:1)
在标题包括.it之前检查你的间距。重定向时可能会导致错误。另一个解决方案是检查你的输出缓冲
你输出缓冲设置为关闭还是开启。
要检查这到你的服务器php.ini文件并检查输出缓冲。如果它关闭然后设置它
如果你没有多余的东西来编辑php.ini文件,你也可以输入以下代码
<?php ob_start();?>
您必须为每个页面编写此代码
并关闭输出缓冲
输入<?php ob_end_flush();?>
答案 1 :(得分:0)
因为你在标题之前输出了文本(可能是一个空白行)。在您发布的示例中,它将输出?&gt;之间的空白行。和
答案 2 :(得分:-1)
翻译者:Google Translator采用创新的超级技术来检测语言并翻译成英语 对于:d4Rk
我认为这会解决:
<?php
//if the session is not unset and expired yet
if ( isset($_SESSION['expire']) && ($now<= $_SESSION['expire'])):
?>
do sth...
<?php
else {
//unset the session and redirect to index.php again
unset($_SESSION['expire']);
session_destroy();
header('location:../index.php');}
endif
?>