PHP - 无法修改标题信息 [英] PHP - Cannot modify header information

查看:130
本文介绍了PHP - 无法修改标题信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要疯了这个错误:无法修改标题信息 - 标题已经发送...



请注意,我知道谷歌gazillion结果和堆栈溢出。我的问题是我构建页面的方式。为了保持html与PHP分开,我使用包含文件。因此,例如,我的页面看起来像这样:

 <?php 
require_once('web.config .PHP');
?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>登入< / title>
< link rel =快捷图标href =images / favicon.gif/>
< link rel =快捷图标href =images / favicon.ico/>
< link rel =stylesheettype =text / csshref =<?php echo SITE_STYLE;?>/>
< / head>
< body>
< div id =page_effectstyle =display:none;>
<?php require_once('./ controls / login / login.control.php'); ?>
< / div>
< / body>
< / html>

所以,当我的php文件被包含时,头文件已经发送。



包含文件的一部分如下所示:

  // //重定向到目标
if($ user_redirect!='default')
{
header('Location:'。$ user_redirect);
}
elseif($ user_redirect =='default'&& isset($ _ GET ['ReturnURL']))
{
$ destination_url = $ _GET ['ReturnURL ];
header('Location:'。$ destination_url);
}
else
{
header('Location:'。SITE_URL.'login.php');
}

但我无法弄清楚如何解决这个问题。我无法在输出之前重定向标题,因此输出缓冲是我能做的唯一事情。当然,它的工作方式很好 - 但不得不依赖于它。



如果PHP有另一种重定向方式或有其他参数来告诉它清除缓冲区。

解决方案 在标头之前是否有任何echo / print语句语句?这可能会导致此错误。


I am going crazy with this error: Cannot modify header information - headers already sent by...

Please note that I know about the gazillion results on google and on stack overflow. My problem is the way I've constructed my pages. To keep html separate from php, I use include files. So, for example, my pages look something like this:

<?php 
require_once('web.config.php'); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="shortcut icon" href="images/favicon.gif"/>
<link rel="shortcut icon" href="images/favicon.ico"/>
<link rel="stylesheet" type="text/css" href="<?php echo SITE_STYLE; ?>"/>
</head>
<body>
<div id="page_effect" style="display:none;">
<?php require_once('./controls/login/login.control.php'); ?>
</div>
</body>
</html>

So, by the time my php file is included, the header is already sent.

Part of the include file looks like this:

// redirect to destination
if($user_redirect != 'default')
{
    header('Location:'.$user_redirect);
}
elseif($user_redirect == 'default' && isset($_GET['ReturnURL']))
{
    $destination_url = $_GET['ReturnURL'];
    header('Location:'.$destination_url);
}
else
{
    header('Location:'.SITE_URL.'login.php');
}

But I can't figure out how to work around this. I can't have the header redirect before the output so having output buffering on is the only thing I can do. Naturally it works fine that way - but having to rely on that just stinks.

It would be nice if PHP had an alternative way to redirect or had additional parameters to tell it to clear the buffer.

解决方案

Is there any echo/print statement before the header statements? That could cause this error.

这篇关于PHP - 无法修改标题信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆