Connecting Tech Pros Worldwide Help | Site Map

Trap server error (e.g. 404) with php

Robertico
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

Is it possible to trap a (web)server error (e.g. 404) with php.
I have one custom error page (php) for all the server errors.
So i want to know with error number occurs.

Regards,

Robertcio


fackelkind
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Trap server error (e.g. 404) with php


My english is not that good, but hope i understood you.

If you have an errorpage for all errors, you already know .htaccess files,
yeah?

In your .htaccess file you can refere an errorpage by doing this:

ErrorDocument 404 error.php?code=404


Robertico
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Trap server error (e.g. 404) with php


> My english is not that good, but hope i understood you.
Me either :-))
[color=blue]
> If you have an errorpage for all errors, you already know .htaccess files,
> yeah?[/color]
I use my httpd.conf file.
[color=blue]
> In your .htaccess file you can refere an errorpage by doing this:
> ErrorDocument 404 error.php?code=404[/color]
How can i trap this in my php page ? (i'am new to php)

Robertico



fackelkind
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Trap server error (e.g. 404) with php


> How can i trap this in my php page ? (i'am new to php)

Ahh thats the point!
You can catch the variable by doing this:

<?php
switch ($_GET["code"]){
case 404:
echo "Page not founded";
break;
case 403:
echo "Forbidden";
break;
case 500:
echo "Servererror";
break;
default:
echo "An unknown error occoured";
}
?>


Robertico
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Trap server error (e.g. 404) with php


Thx, works fine.

Where can i found more information about this ? (this specific item)

Robertico


fackelkind
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Trap server error (e.g. 404) with php


http://php.net/switch


fackelkind
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Trap server error (e.g. 404) with php


http://php.net/switch


Robertico
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Trap server error (e.g. 404) with php


Thx.
Great resource.

Robertico


Closed Thread