View previous topic :: View next topic |
Author |
Message |
PWD -
Joined: 04 Jan 2005 Posts: 34 Location: trying to conquer these fears I thought were GONE
|
Posted: Sat Feb 19, 2005 7:22 am Post subject: Help with custom error pages... |
|
|
I've been running Abyss now for quite some time and am just getting around to setting up some custom error pages.
I set the error number and the custom error page path for each of my errors(400, 401, 403, 500...etc.) under Server Config=>Custom Error Pages and when I type in a non existant page into my browser, it comes up as the following AND displays my html code as if you had gone to "View Page Source":
Code: | "Undefined index: QUERY_STRING at c:\file\abyss\error.php" |
Yet when I type the query string info directly into my browser as :
Code: | http://localhost/error.php?404 |
It displays my Custom Error Page just fine?
I know I've been up feeding my PHP addiction for some time this evening, but what am I doing wrong?
Here is my custom error script:
Code: | <?php
$customerror = $_SERVER['QUERY_STRING'];
switch($customerror) {
case '400':
$errormsg = "<h1>Bad Request (Error Code 400)</h1>";
$errormsg .= "<p>Your Web Browser has made a bad request. <br>";
$errormsg .= "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
$errormsg .= "if you find this message to be an error.</p>";
break;
case '401':
$errormsg = "<h1>Authorization Required! (Error Code 401)</h1>";
$errormsg .= "You have supplied the wrong information to access a secure area. <br>";
$errormsg .= "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
$errormsg .= "if you find this message to be an error.</p>";
break;
case '403':
$errormsg = "<h1>Forbidden Access! (Error Code 403)</h1>";
$errormsg .= "You are <span class=\"red\">DENIED ACCESS</span> to this page! <br>";
$errormsg .= "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
$errormsg .= "if you find this message to be an error.</p>";
break;
case '404':
$errormsg = "<h1>Page Not Found (Error Code 404)</h1>";
$errormsg .= "The page you're attempting to access was not found. <br>";
$errormsg .= "This could be for one of the following reasons: <br>";
$errormsg .= "<ul>";
$errormsg .= "<li>The page is not yet completed.</li>";
$errormsg .= "<li>The address you typed into your browser was not a valid address.</li>";
$errormsg .= "<li>Aliens have abducted the requested page, are probing it for reproductive function and have yet to return it.</li>";
$errormsg .= "</ul>";
$errormsg .= "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
$errormsg .= "if you find this message to be an error.</p>";
break;
case '500':
$errormsg = "<h1>Internal Server Error</h1>";
$errormsg .= "The Server has encountered an internal error. <br>";
$errormsg .= "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
$errormsg .= "if you find this message to be an error.</p>";
break;
}
?> |
Thanks for remembering when you were a novice and helping me learn; so one day I can give as freely as you have given to me here today!
Thanks for helping me learn!
Sincerely,
PWD |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sat Feb 19, 2005 9:14 am Post subject: |
|
|
I fixed your code , just one question , why did you keep changing the variable
$errormsg on every line ? You need to use echo or print to show your HTML. :/
Code: |
<?php
$customerror = $_SERVER['QUERY_STRING'];
switch($customerror) {
case '400':
echo "<h1>Bad Request (Error Code 400)</h1>";
echo "<p>Your Web Browser has made a bad request. <br>";
echo "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
echo "if you find this message to be an error.</p>";
break;
case '401':
echo "<h1>Authorization Required! (Error Code 401)</h1>";
echo "You have supplied the wrong information to access a secure area. <br>";
echo "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
echo "if you find this message to be an error.</p>";
break;
case '403':
echo "<h1>Forbidden Access! (Error Code 403)</h1>";
echo "You are <span class=\"red\">DENIED ACCESS</span> to this page! <br>";
echo "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
echo "if you find this message to be an error.</p>";
break;
case '404':
echo "<h1>Page Not Found (Error Code 404)</h1>";
echo "The page you're attempting to access was not found. <br>";
echo "This could be for one of the following reasons: <br>";
echo "<ul>";
echo "<li>The page is not yet completed.</li>";
echo "<li>The address you typed into your browser was not a valid address.</li>";
echo "<li>Aliens have abducted the requested page, are probing it for reproductive function and have yet to return it.</li>";
echo "</ul>";
echo "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
echo "if you find this message to be an error.</p>";
break;
case '500':
echo "<h1>Internal Server Error</h1>";
echo "The Server has encountered an internal error. <br>";
echo "Please <a href=\"mailto:prowebdesign@frontiernet.net\">CONTACT</a> the site administrator <br>";
echo "if you find this message to be an error.</p>";
break;
default:
echo "<b>This is not a proper error repsonse!</b>";
break;
}
?> |
Note: I added some new code just in case someone tries to type a wrong
error tag that doesn't exist , this is just helpful so you have a default msg.
Last edited by TRUSTAbyss on Sat Feb 19, 2005 9:33 am; edited 4 times in total |
|
Back to top |
|
|
PWD -
Joined: 04 Jan 2005 Posts: 34 Location: trying to conquer these fears I thought were GONE
|
Posted: Sat Feb 19, 2005 9:26 am Post subject: |
|
|
Sorry,
I'm sure that took you some time, I failed to mention right below my script I do have:
Code: | <html>
<head>css info, links, etc here</head>
<body>
//Exact code
<?php echo $errormsg; ?>
</body>
</html> |
Still having trouble...Funny thing is, when I switch the value of my $_SERVER index from:
Code: | $_SERVER['QUERY_STRING']
to
$_SERVER['REDIRECT_STATUS']
AND then change
<?php echo $errormsg; ?>
to
<?php echo $customerror; ?>
|
My html/css and graphics show up fine with zero errors but the script has written "200" on my page! (Which ironically is what my CGI Env. Var is set to under server config!
PWD |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sat Feb 19, 2005 9:33 am Post subject: |
|
|
You need to understand that your code is still kind of wrong , even though your
appending a new msg to $errormsg , your changing that variable , the best way
to fix this is to just echo your HTML like I showed you , look at the top for new
code that I added just incase someone types an invalid error number.
Sincerely , TRUSTpunk |
|
Back to top |
|
|
PWD -
Joined: 04 Jan 2005 Posts: 34 Location: trying to conquer these fears I thought were GONE
|
Posted: Sat Feb 19, 2005 9:58 am Post subject: |
|
|
I double checked your version, and the server still isn't passing the error code to the script (Unless I type http:/ mysite/error.php?404).
Am I using the wrong $_SERVER argument? My paths seem to be setup fine in my custom error config as when I type them in the url, the appropriate response is given by my script.
hmmmm
PWD |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sat Feb 19, 2005 10:15 am Post subject: |
|
|
Can you put this script online so I can check to see what happens because my
script version works fine , I provided an example on setting up an error page.
My Setup
Error code: 404
URL: /error.php?404 |
|
Back to top |
|
|
PWD -
Joined: 04 Jan 2005 Posts: 34 Location: trying to conquer these fears I thought were GONE
|
Posted: Sat Feb 19, 2005 6:19 pm Post subject: |
|
|
Wow..I'm humbled. I simply forgot the ?404 at the end of my url!
Thanks for your time TrustPunk..always grateful.
Sincerely,
PWD |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sat Feb 19, 2005 9:39 pm Post subject: Re: Help with custom error pages... |
|
|
PWD,
The error code is exported in the variable REDIRECT_STATUS. Since this same variable should be configured in CGI Parameters to make PHP run correctly, it is always set to 200.
But the above holds only for versions 1.x. Starting from version 2.0, you have another new variable REDIRECT_STATUS_CODE which contains also the error code. So you can get its value from $_SERVER['REDIRECT_STATUS_CODE'] . _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
etorvinen -
Joined: 02 Jan 2005 Posts: 31
|
Posted: Fri Feb 10, 2006 9:31 pm Post subject: RE |
|
|
Is there a varible for Anti-Leeching or hotlinking lfor example...
php has Code: | $_SERVER['REDIRECT_STATUS_CODE'] | to display either 404, 500 and so on.. Is there any var that controls hotlinking of files then i can add to my error script? _________________ ;@ |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sat Feb 11, 2006 12:27 am Post subject: |
|
|
No. The variable that you should use is the HTTP_REFERER, which can be used
to see what site someone is coming from to download the file, like if it doesn't
belong to your site address, you can send them an anti-leech error (403).
Note: Abyss Web Server has an anti-leech feature already, and it uses the exact
same method im talking about in this forum reply. Hopefully this info helped. :-)
Sincerely, TRUSTpunk |
|
Back to top |
|
|
|