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()?

3
  • remove the line - <!DOCTYPE html> Commented Jul 12, 2013 at 17:34
  • possible duplicate of Headers already sent by PHP Commented Jul 12, 2013 at 17:36
  • remove everything in the file except <?php header('Location:http://www.website.com/index.php?page=404.php', true, 302); Commented Jul 12, 2013 at 17:37

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

6 Comments

Well, I tried moving the PHP before the doctype, but then when I load the page it says ERROR 403: Forbidden.
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 <your php file name>
I can copy/paste the location target URL into the address bar and it loads just fine.
@user2577320 - try replacing the URL with something that definitely works. Clearly, the original error is solved. Can you post the URL?
I just tried changing the target URL with google.com, and it still says forbidden. The test URL is side7entertainment.org
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.