JonMorehouse
JonMorehouse

Reputation: 1383

Send 404 header after page load

I'm trying to send a 404 header after the page loads and was wondering if there were any solutions. Essentially, a database is searched to see if the url is valid and corresponds to valid content. If it doesn't, it will "include()" an error.php file.

Is there anyway that I can write an htaccess rule that says, whenever this file is loaded, throw a 404? How else could I send that 404 inside of the error.php file, since it is not the first thing to be displayed?

Upvotes: 0

Views: 1053

Answers (2)

Alfo
Alfo

Reputation: 4819

Call this first on error.php, before outputting any error text.

<?php
    header("HTTP/1.0 404 Not Found");
?>

Upvotes: 3

Daniel Figueroa
Daniel Figueroa

Reputation: 10666

You can always use the header-function, just remember to do that before you output anything else.

I would recomend doing that instead of including another file, and then configure your server to serve an appropiate 404 file.

PHP docs header function

Upvotes: 1

Related Questions