Random HTTP Error Messages Script

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
etorvinen
-


Joined: 02 Jan 2005
Posts: 31

PostPosted: Wed Nov 16, 2005 3:39 pm    Post subject: Random HTTP Error Messages Script Reply with quote

I am trying to create a script to dectect what kind of error depending if it is a 404 to a 500. I am having trouble finding out the code because the same code that is used with apache does not work with abyss.

The code that i created is listed below the only way i was able to get this to work is to post a var such as error= something. it would look like this with in the server:
/errors/defaulterror.php?error=404
that will generate a costom 404 Error.

Code:

<?PHP
// This code was created by Eric Torvinen
// E-Mail etorvinen@gmail.com
if(isset($HTTP_POST_VARS["error"]))
{
$error = ('".$_POST["error"]."');
};
if ($error == "400") {
$titleerror = ".: HTTP 400 :: BAD REQUEST :.";
$picture =
"
Your browser has just sent a bad request... You can either hit refresh or click the link below...<br>
<img src='/errors/images/imgerrors/405.gif' alt='Error 405' width='791' height='404' border='1'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};
if ($error == "401") {
$titleerror = ".: HTTP 401 :: Unauthorized Access :.";
$picture = "<img src='/errors/images/imgerrors/401Unauthorized.jpg' alt='Error 401' width='500' height='400'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};
if ($error == "403") {
$titleerror = ".: HTTP 403 :: FORBIDDEN :.";
$picture = "<img src='/errors/images/imgerrors/403Fobidden.jpg' alt='Error 403 width='500' height='400'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};
if ($error == "404") {
$titleerror = ".: HTTP 404 :: File Not File On Server :.";
$picture = "<img src='/errors/images/imgerrors/404NotFound.jpg' alt='Error 404' width='500' height='400'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};
if ($error == "405") {
$titleerror = ".: HTTP 405 :: Resource not allowed :.";
$picture = "<img src='/errors/images/imgerrors/405.gif' alt='Error 405' width='791' height='404' border='1'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
echo "<center><h1>Resource temporary out of order! STAND BY!</h1></center>";
};
if ($error == "500") {
$titleerror = ".: HTTP 500. Internal Server Error :: THIS SERVER HAS ENCOUNTERED AN INTERNAL ERROR :.";
$picture = "<img src='/errors/images/imgerrors/500InternalServerError.jpg' alt='Error 500' width='500' height='400'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};
if ($error == "503") {
$titleerror = ".: HTTP 503 :: Service Temperarily Unavailable :.";
$picture = "<img src='/errors/images/imgerrors/503ServiceTemperarilyUnavailable.jpg' alt='Error 503' width='500' height='400'>";
$redirect = "Please <span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
<a href='/'><font color='#000000'>click here</a></font></span> to be redirected!";
};


if ($error == "redirect") {
$titleerror = ".: HTTP 503 :: Service Temperarily Unavailable :.";
$picture = "<img src='/errors/images/imgerrors/503ServiceTemperarilyUnavailable.jpg' alt='Error 503' width='500' height='400'>";
$redirect = "";
};
if ($error == "") {
$titleerror = "Error: UNKNOWN";
$picture = "An Unknown error occured please contact the admin.<br>";
$redirect = "<span style='font-variant: small-caps; font-style: italic; text-decoration: underline'>
 <a href='/mail'><font color='#000000'>Please Contact WebMaster</a></font></span>";
};
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title><? echo "$titleerror"; ?></title>
</head>

<body>
<div align="center"><? echo "$titleerror"; echo "<br>$picture"; ?>
</div>
<p align="center"><font size="4" color="#000000">

<? echo "$redirect"; ?>
</font></p>

</body>
</html>

Can someone help
_________________
;@
Back to top View user's profile Send private message
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Wed Nov 16, 2005 4:43 pm    Post subject: Reply with quote

I'm unclear as to what doesn't work. Can you explain a little better?

And you might find it easier to use a switch instead of all those ifs.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Nov 17, 2005 12:22 pm    Post subject: Re: Random HTTP Error Messages Script Reply with quote

etorvinen,

When a custom error page is "called", the value of the error code is stored in a special variable. See http://www.aprelium.com/forum/viewtopic.php?p=36450#36450 for more information.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
etorvinen
-


Joined: 02 Jan 2005
Posts: 31

PostPosted: Sun Mar 05, 2006 5:31 pm    Post subject: RE: Reply with quote

Thanks that is what i was tring to find out. What i was trying to do is to use a varible for example.


In the picture varible,

Code:

<img src='/images/404.gif'>
to
<? PHP echo "<img src='/images/$errorcode.gif'>"; ?>

That was i can remove all the if statements and keep one line of code.

It makes the script easer to read, disasemble, and troubleshoot when something bad happens.

If you want to see my revised code please e-mail me at etorvinen@gmail.com.
Thanks this forum really helped.


_________________
;@
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group