douyousu9691 2010-12-24 06:47
浏览 32
已采纳

PHP - 无法修改标题信息[重复]

This question already has an answer here:

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.

</div>
  • 写回答

3条回答 默认 最新

  • dppxp79175 2010-12-24 06:53
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改