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
jchannon
Forum Newbie
Posts: 12 Joined: Fri Aug 03, 2007 1:55 pm
Post
by jchannon » Fri Jan 23, 2009 7:03 am
Hi,
I have spent hours trying to get all this to work with no luck so was after some help.
I have a content based site where I check if the pagename exists and if it doesn't I do the following:
Code: Select all
if (!$pageFound)
{
header("HTTP/1.0 404 Not Found");
}
However if I check the response headers I get 200 OK.
That is the first issue.
At the moment I have rewriting turned on so at the moment a url of
http://www.domain.com/testpage.html gets rewritten to
http://www.domain.com?index.php?page=testpage
If they type something in like
http://www.domain.com/pagenotexist.html it will run the above code and return a 404 header.
How can I handle these scenarios?
Thanks
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Jan 23, 2009 7:07 am
Code: Select all
if (!$pageFound)
{
header("HTTP/1.0 404 Not Found");
exit();
}
There are 10 types of people in this world, those who understand binary and those who don't
jchannon
Forum Newbie
Posts: 12 Joined: Fri Aug 03, 2007 1:55 pm
Post
by jchannon » Fri Jan 23, 2009 7:15 am
That makes no difference.
I have tried all combinations of exit and die.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Jan 23, 2009 7:21 am
Are you sure this code block gets executed?
There are 10 types of people in this world, those who understand binary and those who don't
jchannon
Forum Newbie
Posts: 12 Joined: Fri Aug 03, 2007 1:55 pm
Post
by jchannon » Fri Jan 23, 2009 7:31 am
Yes because I get a blank white screen in Firefox which I assume is the header kicking in.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Jan 23, 2009 7:32 am
Code: Select all
if (!$pageFound)
{
error_log()
header("HTTP/1.0 404 Not Found");
exit();
}
and check if '404 header sent.' appears in your error logs.
There are 10 types of people in this world, those who understand binary and those who don't
jchannon
Forum Newbie
Posts: 12 Joined: Fri Aug 03, 2007 1:55 pm
Post
by jchannon » Fri Jan 23, 2009 7:46 am
Nothing appears in the error_log file regarding a 404, you have to supply a message to that function and that message appears.
In the log file for today there is reference to the 404 errors
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Jan 23, 2009 8:09 am
Yeah,
cut &paste error
Code: Select all
if (!$pageFound)
{
error_log( '404 header sent.');
header("HTTP/1.0 404 Not Found");
exit();
}
So ... do you see the exact "404 header sent." message in your error logs? Any other messages regrading 404 are out of interest.
There are 10 types of people in this world, those who understand binary and those who don't
jchannon
Forum Newbie
Posts: 12 Joined: Fri Aug 03, 2007 1:55 pm
Post
by jchannon » Fri Jan 23, 2009 8:16 am
Yes I see that message!
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Jan 23, 2009 9:45 am
Are there any "headers already sent" messages in your error log?
There are 10 types of people in this world, those who understand binary and those who don't