使用PHP header()的奇怪错误

Rei*_*n S 0 html php header

我收到以下错误:

警告:无法修改标题信息 - 已在第4行的/home/content/89/11421189/html/notfound.php中发送的标题(在/home/content/89/11421189/html/notfound.php:2处开始输出)

在我的文件'notfound.php'中,它使用以下代码:

<!DOCTYPE html>
<?php//Line 2
ob_start();
header('Location:http://www.website.com/index.php?page=404.php', true, 302);
exit;
?>
<head>
</head>
<html>
</html>
Run Code Online (Sandbox Code Playgroud)

请注意,PHP标记之前或之后没有空格.无论我将它移动到哪里(即使它都在同一条线上),该行是错误的罪魁祸首.我在这做错了什么?

[编辑]注意:如果我将PHP移动到DOCTYPE标记之前,导航到此文件会给出错误403:禁止.位置很好,因为我可以将其复制/粘贴到地址栏中而不会出现问题.你能通过header()传递GET参数吗?

mar*_*ite 6

输出任何内容后,您无法输出标题.DOCTYPE在header()之前输出.