0

I'm getting the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/89/11421189/html/notfound.php:2) in /home/content/89/11421189/html/notfound.php on line 4

In my file 'notfound.php', which uses the code below:

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

Note that there is NO whitespace before the PHP tag, or AFTER it. No matter where I move it to (even if it's all on the same line), that line is the culprit in the error. What am I doing wrong here?

[EDIT] Note: If I move the PHP to before the DOCTYPE tag, navigating to this file gives me an error 403: forbidden. The location is fine, since I can copy/paste it into the address bar without issues. Can you not pass GET arguments through header()?

Rein S
  • 889
  • 6
  • 18

1 Answers1

6

You can't output headers after anything has been output. The DOCTYPE is output before the header().

markdwhite
  • 2,360
  • 19
  • 24
  • Well, I tried moving the PHP before the doctype, but then when I load the page it says ERROR 403: Forbidden. – Rein S Jul 12 '13 at 17:34
  • in that case maybe you need to change the mode of your file to 777 ie if your are using linux just execute this command - chmod 777 – saran banerjee Jul 12 '13 at 17:37
  • I can copy/paste the location target URL into the address bar and it loads just fine. – Rein S Jul 12 '13 at 17:37
  • @user2577320 - try replacing the URL with something that definitely works. Clearly, the original error is solved. Can you post the URL? – markdwhite Jul 12 '13 at 17:39
  • I just tried changing the target URL with http://www.google.com, and it still says forbidden. The test URL is side7entertainment.org – Rein S Jul 12 '13 at 17:41
  • Hello @user2577320. It appears that markdwhite has solved the original issue. You should mark his solution as solved. If you are getting a 403 error now that will be b/c you either have the permissions wrong but most likely an incorrect url. http://stackoverflow.com/questions/1300125/php-script-403-forbidden-error – Chris78 Jul 12 '13 at 17:43