Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
页眉(';位置:index.php';)在刷新页面2次后将我重定向到index.php_Php_Session_Redirect_Header_Unset - Fatal编程技术网

页眉(';位置:index.php';)在刷新页面2次后将我重定向到index.php

页眉(';位置:index.php';)在刷新页面2次后将我重定向到index.php,php,session,redirect,header,unset,Php,Session,Redirect,Header,Unset,我有一个php页面(index.php),在验证用户名和密码后,将设置一个会话($_session['expire']),该会话将在30分钟后(按下登录按钮后30分钟)过期并取消设置,并将再次重定向到index.php: header('location:index.php'); 验证后,索引页中将显示一个菜单,其中一项是ContentManager.php。 如下所示,单击此项,我们将连接到数据库并进入contentmanager.php switch($_REQUEST['action']

我有一个php页面(index.php),在验证用户名和密码后,将设置一个会话($_session['expire']),该会话将在30分钟后(按下登录按钮后30分钟)过期并取消设置,并将再次重定向到index.php:

header('location:index.php');
验证后,索引页中将显示一个菜单,其中一项是ContentManager.php。 如下所示,单击此项,我们将连接到数据库并进入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”两次才能重定向到index.php 如果我只按一次,就会显示一个空白页。但通过第二次刷新页面,它将再次重定向到登录页面(index.php)


请帮助我…

这是因为您在标题前输出文本(可能是一个空行)。在您发布的示例中,它将在“>”和“

之间输出空白行”,在标题之前检查间隔。在重定向时可能会导致错误。另一个解决方案是检查<强>输出缓冲< <强> >。 您是否将输出缓冲设置为关闭或打开。 要检查这一点,请访问您的服务器php.ini文件并检查输出缓冲。如果关闭,则将其设置为打开 如果您没有多余的内容来编辑php.ini文件,您还可以在此基础上键入以下代码

您必须为每个页面编写此代码 并关闭输出缓冲
键入

我认为这将解决:

<?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
?>

做某事。。。

退出
标题(…)之后(…)
抱歉,但它不起作用,
过期设置为什么?这不是你写的30分钟解释吗?我删除了所有空白行,但没有帮助。