dongyimeng3764 2013-01-21 12:51
浏览 12
已采纳

无法修改收到的标题信息错误[重复]

Possible Duplicate:
PHP error: Cannot modify header information – headers already sent
Headers already sent by PHP

if ((isset($username)) && (isset($userid))){ 

}else{ 

header( 'Location: teacherlogout.php' ) ;

}

I have an if/else statement above, what I want to do is that if the else statement is met, then navogate to the teacherlogout.php page. But instead of this I am getting an error stating:

Warning: Cannot modify header information - headers already sent by (output started at /:431) in / on line 1654 

I don't quite get what I am doing wrong? Line 431 is just a var qremain = <?php echo (int)$_SESSION['textQuestion']; ?>; line of code. Line 1654 is the header( 'Location: teacherlogout.php' ) ; line. What is happeing here?

UPDATE:

Actually will it be better to use ajax to navigate to teacherlogout.php script in background as so:

<?php   

}else{ 

echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";

?>

<script type="text/javascript">

        $.ajax({    
        url: "teacherlogout.php",
        async: false,
        type: "POST",
      });

</script>

<?php

}

?>
  • 写回答

3条回答 默认 最新

  • dongzhizhai4070 2013-01-21 12:56
    关注
    Cause:
    

    This error is caused if the your PHP scripts are printing to the browser prior to sending headers. A common example is printing the html tags prior to starting a session, or setting a cookie. The error tells the line that needs to be altered (in this case, it is on line 431).

    Resolution:
    

    To resolve this error remove the lines from the PHP code that are printing to the browser prior to sending headers.

    Another common cause for this error is white space either at the beginning or end of the file. The fix is to remove that whitespace from the file. Read the error message carefully. It says output started at ... followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one.

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

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写