header("HTTP/1.1 404 Not Found"); shows only empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pospiech
Forum Newbie
Posts: 5
Joined: Fri Mar 12, 2004 8:35 am

header("HTTP/1.1 404 Not Found"); shows only empty

Post by pospiech »

I found the command
header("HTTP/1.1 404 Not Found");
for displaying that a page was nto found.
It however produces only an empty page.

Is the code wrong, or what is the problem ?

Matthias Pospiech
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: header("HTTP/1.1 404 Not Found"); shows only e

Post by TheBentinel.com »

pospiech wrote:I found the command
header("HTTP/1.1 404 Not Found");
for displaying that a page was nto found.
It however produces only an empty page.

Is the code wrong, or what is the problem ?

Matthias Pospiech
The header is only seen by the browser, it isn't displayed to the user. You would also need to put in some sort of "Sorry, we don't have a file like that" text. You may not need to send any header info, your server probably is handling that for you. I have a custom 404 page on my site, but it's static HTML. The server throws it at you if you request a file that doesn't exist, and adds a 404 header automatically. (Linux/Apache)
pospiech
Forum Newbie
Posts: 5
Joined: Fri Mar 12, 2004 8:35 am

Post by pospiech »

The reason I need it, is that other wise php will send an error to the page that it did not find a file.
Now I check and want to send a 404 Page instead - with this command. It however presents only an empty page.

Matthias
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

pospiech wrote:The reason I need it, is that other wise php will send an error to the page that it did not find a file.
Now I check and want to send a 404 Page instead - with this command. It however presents only an empty page.

Matthias
That's cool. Just put some text in the page. Whatever you want to say to your users. Since I run a site with various articles, I put my current article headlines on my 404 page. If somebody mistypes a url, they at least get a page that represents my site and suggests articles they might want to read.

Treat it like any other PHP page on your site, except you include whatever headers you want before outputting any HTML.

Or am I missing your point altogether? If I am, I'm sorry. Feel free to knock me back on track.
pospiech
Forum Newbie
Posts: 5
Joined: Fri Mar 12, 2004 8:35 am

Post by pospiech »

Well I agree with your point completely - I just still would be interested to know why I do not get the 404 Page to my browser.
For the project itsself this will be replaced by an appropiate site as you suggested.

Matthias
Post Reply