Jump to content


Photo

PHP force 404 Error


  • Please log in to reply
8 replies to this topic

#1 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 01 September 2006 - 04:44 PM

I want certain pages to return the 404 error page that the server automatically generates. I tried the following code and it didn't work, what am I doing wrong?

My Code:
header("HTTP/1.1 404 Not Found");

Thanks.

#2 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 04:54 PM

have you got a die/exit immediately after that?

#3 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 01 September 2006 - 04:55 PM

Yes.

#4 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 01 September 2006 - 05:22 PM

The whole file just looks like this -
<?
header("HTTP/1.1 404 Not Found");
exit;
?>


#5 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 September 2006 - 05:42 PM

If you're trying to create you're own Custom 404 Pages, you'll have to edit the 404.shtml in your Apache or IIS configuration

Most of the time you can just have all you're error pages do the same thing and just send the error message to one of you're PHP scripts along with whatever information you want.
But you have to do that in that 404.shtml file

That is if that's what you're trying to do

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#6 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 01 September 2006 - 05:51 PM

No. I have the error pages working fine. I just want PHP to output my servers 404 on a page that does. Exist so that I can force the error page for invalid query strings etc.

#7 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 September 2006 - 06:03 PM

Well, I guess if you're not going to have anything else on the error page other than......the 404

you could just flat out redirect to ajflkjdslfkjsdlkajflakf.html
which I'd assume doesn't exist

but you'd do it through HTML and not a PHP function....meaning
echo out

<META http-equiv="refresh" content="0; URL=somerandomarrayofletters.html">


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#8 Millar

Millar
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts
  • LocationSouthampton, UK.

Posted 01 September 2006 - 06:08 PM

Well id rather do it via the proper way. Anyone know why its not working?

#9 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 01 September 2006 - 06:37 PM

Would it not be confusing for a user to send a 404 error for something like a bad query string? Would it not be better to give them a message saying what the problem was etc?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users