View Full Version : Custom error-handler based on vBulletin templates
AlexanderT
05-10-2004, 10:00 PM
What this hack does?
---------------------------
UPDATE: Improved instruction.txt, fixed for those who use external style sheets
This hack adds a custom error-handler to your site using the vBulletin template engine to display the appropriate errors (e.g. 404 File not Found, 403 Forbidden, etc).
Demo
-------
Go to my site and enter some non-existing url. E.g. Random 404 Error (http://www.mobileread.com/doesntexist.php). Or try to access my /cgi-bin (http://www.mobileread.com/cgi-bin/) path to receive a 403 error.
What to do?
----------------
queries to run: 0
templates changed: 0
templates added: 1 (ERROR_SHELL)
files changed: 1 (.htaccess)
files added: 1 (error.php)
Time needed to install
----------------------------
< 5 mins
Boofo
05-11-2004, 06:46 PM
Ahhh, a new toy for me to play with. Thank you very much, sir. ;)
* Boofo clicks the install button continuously!
sabret00the
05-11-2004, 06:52 PM
beautiful :)
Intex
05-11-2004, 07:28 PM
Nice work. I'll add to my install list :cool:.
Boofo
05-11-2004, 07:39 PM
I'm having a strange problem with my style background not showing as well as the alt1 and alt2 variables. :(
Preech
05-11-2004, 08:39 PM
I can't get this to work. I know it has something to do with how I'm doing the htaccess file.
FleaBag
05-11-2004, 09:33 PM
Same here. When I install it every page get's a 500 error. Everything is in my root folder, I commented out the chmod line but to no avail.
Boofo
05-11-2004, 09:38 PM
I'm having a strange problem with my style background not showing as well as the alt1 and alt2 variables. :(
If the error.php file is accessed from my forums directory, it looks like it is supposed to. If it is accessed from my home page, that is where I have the problem with the background of my styles not showing and making the page look wierd. Anyone have any ideas how to fix this? ;)
Dankinit
05-11-2004, 09:40 PM
You might want to take out custom code in that error.php and re-release it...
Also a side note to anybody installing it, if you haven't put absolute paths to your navbar links, you'll see they point to incorrect files.
Dankinit
05-11-2004, 09:42 PM
If the error.php file is accessed from my forums directory, it looks like it is supposed to. If it is accessed from my home page, that is where I have the problem with the background of my styles not showing and making the page look wierd. Anyone have any ideas how to fix this? ;)
Sounds like it's looking in the wrong place for the css file. I think i had to hack my board to give it an absolute path for the css file...can't remember though, it was awhile ago. ;)
Boofo
05-11-2004, 09:47 PM
Sounds like it's looking in the wrong place for the css file. I think i had to hack my board to give it an absolute path for the css file...can't remember though, it was awhile ago. ;)
Where would I have to give the path for that at? Do you remember? ;)
What's wierd is that my home page doesn't have a problem with it.
GamerJunk.net
05-12-2004, 04:59 AM
Good hack, but my host already lets me make my own error pages so I could easily do this without the hack.
Great job though!
MrNase
05-12-2004, 05:04 AM
I don't know if it validates but placing
<base href="http://www.sportboard.de" />
above </header> makes all links have an absolut path :)
test.html goes to http://www.sportboard.de/test.html and even a relative link to a stylesheet should change.
Pure magic ;)
colicab-d
05-12-2004, 05:11 AM
oooh now this is handy :) thnx very much :)
AlexanderT
05-12-2004, 06:16 AM
Ok, I updated the hack with improved instruction. Please download again.
@Boofo: Error.php is now copied to your forums path; please re-download the hack. I assume you store CSS stylesheets as files, this is why it didn't work correctly for you.
@Preech/FleaBag: Check the new instruction. Perhaps you need to ask your webhost for assistance.
@Dankinit: Ok, I moved the custom error handling specific to my site to /example/. I included it first place to help people further customizing their error responses.
Greets
Alex
Phalynx
05-12-2004, 07:50 AM
*install*
Boofo
05-12-2004, 09:48 AM
Ok, I updated the hack with improved instruction. Please download again.
@Boofo: Error.php is now copied to your forums path; please re-download the hack. I assume you store CSS stylesheets as files, this is why it didn't work correctly for you.
Greets
Alex
Didn't chnage anything. I still get the same thing on the home page. If I select NO for stylesheets as files, it works fine. But I like to have them as files. :(
AlexanderT
05-12-2004, 10:44 AM
Boofo did you read the new instruction? Earlier you said yourself that "if the error.php file is accessed from my forums directory, it looks like it is supposed to" ?!
Edit: Ahh I think i understand your problem now. I must think again if it is at all possible to support external style sheets like in your case then. Perhaps if you copy the style sheets to your root path, but that would be a pain. Lemme think about it.
Edit2: Could you add <base href="http://www.yoursite.com/yourforum/" /> to the <head> section of the ERROR_SHELL template and see if it does any difference?
Greets
Boofo
05-12-2004, 11:15 AM
Edit2: Could you add <base href="http://www.yoursite.com/yourforum/"> to the <head> section of the ERROR_SHELL template and see if it does any difference?
Greets
That fixed it! Thank you, sir. ;)
Do I need to put a closing </base> anywhere with that?
AlexanderT
05-12-2004, 11:48 AM
That fixed it! Thank you, sir. ;)
Do I need to put a closing </base> anywhere with that?
Cool. I have updated the instruction accordingly. <base> is an empty tag, or a standalone tag, that doesn't use a </base> endtag. The /> at the end is sufficient to make the code xhtml 1.0-valid.
Dankinit
05-12-2004, 12:34 PM
Where would I have to give the path for that at? Do you remember? ;)
This is very useful for anybody writing custom hacks outside of their vb3 base directory and storing css as file:
https://vborg.vbsupport.ru/showthread.php?t=63520
MrNase
05-12-2004, 07:19 PM
Cool. I have updated the instruction accordingly. <base> is an empty tag, or a standalone tag, that doesn't use a </base> endtag. The /> at the end is sufficient to make the code xhtml 1.0-valid.
Nice to see my tip actually worked :)
AlexanderT
05-12-2004, 07:35 PM
Nice to see my tip actually worked :)
Yup, merci for it :)
Synicide
05-12-2004, 09:19 PM
Wow, this is awesome. :D Saves me a LOT of work.
* Synicide clicks install!
Boofo
05-13-2004, 09:39 AM
Wow, this is awesome. :D Saves me a LOT of work.
* Synicide clicks install!
I love the skin on your site. Did you do that? ;)
Synicide
05-13-2004, 12:57 PM
I love the skin on your site. Did you do that? ;)
Yep, that's homemade. :D
Boofo
05-13-2004, 02:33 PM
Yep, that's homemade. :D
Have you thought about releasing it at all? ;)
Natch
05-13-2004, 03:01 PM
Cool. I have updated the instruction accordingly. <base> is an empty tag, or a standalone tag, that doesn't use a </base> endtag. The /> at the end is sufficient to make the code xhtml 1.0-valid.
One useful bit of info :) try <base href="$vboptions[bburl]" /> and it should work across all boards :) you could include that code in your template :)
Also a switch($_SERVER['REDIRECT_STATUS']) would probably be a nicer way to code this ... rather than all those else if's
Just a personal preference thing :)
* Natch clicks install just the same :)
Great idea!
Boofo
05-13-2004, 03:27 PM
One useful bit of info :) try <base href="$vboptions[bburl]" /> and it should work across all boards :) you could include that code in your template :)
Also a switch($_SERVER['REDIRECT_STATUS']) would probably be a nicer way to code this ... rather than all those else if's
Just a personal preference thing :)
* Natch clicks install just the same :)
Great idea!
The $vboptions[bburl] doesn't work for stylesheets as files. I just tested it. You have to have the absolute path for the home page to work right. ;)
How would you set up the switch code?
Natch
05-13-2004, 03:30 PM
As I mentioned in the post above, this code can be more efficient (and easier to add new error codes) witha switch statement:
Find:if(isset($_SERVER['REDIRECT_STATUS']))
{
if ($_SERVER['REDIRECT_STATUS']=="404")
{
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you believe that the mistake is on our part.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="403") {
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="401") {
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="500") {
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us to report this problem.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="503") {
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
else
{
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
}
else
{
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
Replace with:if(!isset($_SERVER['REDIRECT_STATUS']))
{
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
else switch($_SERVER['REDIRECT_STATUS'])
{
case("404"):
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you believe that the mistake is on our part.";
break;
case("403"):
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
break;
case("401"):
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
break;
case("500"):
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us to report this problem.";
break;
case("503"):
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
break;
default:
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
Also (to follow all those W3C tips about the TITLE tags) ...
In the ERROR_SHELL template, find:<title>$vboptions[bbtitle]</title>
Replace with:<title>$error[title] - $vboptions[bbtitle]</title>
UPDATED: thanks Boofo for the heads up about the missing break;
Natch
05-13-2004, 03:33 PM
The $vboptions[bburl] doesn't work for stylesheets as files. I just tested it. You have to have the absolute path for the home page to work right. ;)You're right ... then you could use $vboptions[homeurl]/forums/ but that defeats the purpose of having one template for all ...
How would you set up the switch code?I knoew you would ask :D see above :)
Natch
05-13-2004, 03:35 PM
I believe that Zachery has posted code (https://vborg.vbsupport.ru/showthread.php?t=63520) that gives an absolute path to the link href statement to call stylesheets - that's why I didn't notice it not working ... it did for me :)
Boofo
05-13-2004, 03:58 PM
Witrh Zach's code, I don't need the Base code in the template anymore. Thank you, sir. ;)
Boofo
05-13-2004, 04:08 PM
As I mentioned in the post above, this code can be more efficient (and easier to add new error codes) witha switch statement:
Find:if(isset($_SERVER['REDIRECT_STATUS']))
{
if ($_SERVER['REDIRECT_STATUS']=="404")
{
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you believe that the mistake is on our part.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="403") {
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="401") {
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="500") {
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us to report this problem.";
}
elseif ($_SERVER['REDIRECT_STATUS']=="503") {
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
else
{
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
}
else
{
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
Replace with:if(!isset($_SERVER['REDIRECT_STATUS']))
{
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
else switch($_SERVER['REDIRECT_STATUS'])
{
case("404"):
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you believe that the mistake is on our part.";
break;
case("403"):
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
break;
case("401"):
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you think that there is a mistake.";
break;
case("500"):
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us to report this problem.";
break;
case("503"):
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
default:
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if this problem persists.";
}
Also (to follow all those W3C tips about the TITLE tags) ...
In the ERROR_SHELL template, find:<title>$vboptions[bbtitle]</title>
Replace with:<title>$error[title] - $vboptions[bbtitle]</title>
Shouldn't there be a break before the default line?
paulomt1
05-13-2004, 05:12 PM
Where I can add the 'AllowOverride FileInfo' entry?
Problem already resolved, thanks
Synicide
05-13-2004, 08:41 PM
Have you thought about releasing it at all? ;)
I dunno dude, I kind of like my one of a kind styles. But hey, if I ever feel like coming up with a more generic version of it... I guess I could release it, you think it'd be a good idea?
Boofo
05-13-2004, 09:30 PM
I dunno dude, I kind of like my one of a kind styles. But hey, if I ever feel like coming up with a more generic version of it... I guess I could release it, you think it'd be a good idea?
I think that would be an excellent idea. ;)
ImportPassion
05-19-2004, 02:17 AM
i wasn't using the sendmessage.php, so the link was messed up for contact. that should be an option.
also, it's funny, when you do click the contact us link, it takes u to the contact page and after you send it, it takes u back to the 404 page. ;)
Natch
05-19-2004, 02:23 AM
Shouldn't there be a break before the default line?
Yup - I''ll modify my post to reflect that :) (good debugging)
Boofo
05-19-2004, 02:37 AM
Yup - I''ll modify my post to reflect that :) (good debugging)
Always willing to help a friend out. ;)
Intex
05-29-2004, 09:15 AM
I followed the instructions and it doesn't appear to work for me. I'm using Apache2 on a Windows host.
I've created the .htaccess file and made sure that the Apache httpd.conf file is set to look for .htaccess files and also includes the 'AllowOverride FileInfo AuthConfig Limit' directive. Template was also included and error.php uploaded.
All I get is the usual Windows 404 Error saying page not found.
Any ideas?
Intex
06-01-2004, 11:57 AM
* Bump *
Intex
06-03-2004, 11:36 AM
* Bump @ AlexanderT *
AlexanderT
06-03-2004, 12:04 PM
Intex, sorry for my late reply. I am not sure why it wouldn't work for you. But the again, I haven't really had experience with either Apache 2 or Windows hosts. Can you use .htaccess files in general (like for protection directories)?
Slapyo
06-03-2004, 01:23 PM
can i use this error handler for the forums only, and then a different error handler for my site.
like put a .htaccess in ../
and put your .htaccess in ../forums/
just curious if this is possible or not, or if i should just make the whole site goto the forum error handler. thanks.
0zone
06-08-2004, 12:51 AM
Installed, tested, working as expected.
Thanks for the hack. :)
[clicks install]
AlexanderT
06-08-2004, 07:22 AM
like put a .htaccess in ../
and put your .htaccess in ../forums/
Yes that should work. Have you given it a try?
Slapyo
06-08-2004, 04:23 PM
not yet, unfortunately i am in the middle of finals week so i won't be able to sit down and work on my site until next week some time.
Slapyo
06-28-2004, 12:27 PM
after installing the hack, all i get is:
Unknown Error
We are currently unable to handle this error.
Please contact us if this problem persists.
i tried requesting a file like asdf.html which i don't have on my server and it doesn't give the 404 error. it gives the unknown error. after looking at the code that means that $_SERVER['REDIRECT_STATUS'] isn't being set. everything is setup up according to the install. any ideas?
EDIT: figured it out. in my .htaccess, the link i gave to the error.php file included my URL in front of it ... http://www.mysite.com/forums/error.php ... soon as i changed it to what was shown in the instructions ... /forums/error.php ... it worked like a charm. thanks!
ImportPassion
06-28-2004, 12:38 PM
how do we get this to use whatever skin somebody is using currently?
58sniper
06-29-2004, 09:52 PM
Okay - I was so happy with this hack that I'm going to help improve it. Hopefully, you will find this usefull...
What this does is, for 404 and 500 errors, the server will send you an email notifying you of the error, and providing some information that will assist you in resolving it.
open error.php and find:
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us if you believe that the mistake is on our part.";
under that, paste
$error_message = "An attempt to get a file (". $_SERVER['REQUEST_URI'] . ") failed. Please investigate!\r\n";
if (isset($_SERVER['HTTP_REFERER'])){
$error_message .= "The user came from " . $_SERVER['HTTP_REFERER'] . "\r\n";
if (!preg_match ("/.*?domain.com.*?/i", $_SERVER['HTTP_REFERER'])) {
$error_message .= "You may wish to contact the administrator of that domain.\r\n";
}
}
$error_message .= "User agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
$error_message .= "Remote Address: " . $_SERVER['REMOTE_ADDR'] . "\r\n";
$error_message .= "Remote Port: " . $_SERVER['REMOTE_PORT'] . "\r\n";
find
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"$vboptions[bburl]/$vboptions[contactuslink]\">contact</a> us to report this problem.";
and paste this under it
$error_message = "An attempt to get a file (". $_SERVER['REQUEST_URI'] . ") caused an error. Please investigate!\r\n";
if (isset($_SERVER['HTTP_REFERER'])){
$error_message .= "The user came from " . $_SERVER['HTTP_REFERER'] . "\r\n";
}
find
eval("print_output(\"".fetch_template('ERROR_SHELL')."\");");
and paste this ABOVE it
$error_headers = "";
$error_headers .= "FROM:domain.com Error Manager <errors@domain.com>\n";
$error_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$error_headers .= "X-Mailer: PHP " . phpversion() . "\r\n";
$error_headers .= "Importance: High\r\n";
$error_headers .= "X-Priority: 5 (High)\r\n";
$error_headers .= "Return-Path: <errors@domain.com>\r\n";
if ((($_SERVER['REDIRECT_STATUS']=="404")&&($_SERVER['REQUEST_URI'] != "/error.php?eid=404"))||($_SERVER['REDIRECT_STATUS']=="500")){
$error_subject = $eid . " error!";
$error_mail = mail("webmaster <webmaster@domain.com>","$error_subject","$error_message","$error_headers");
}
IMPORTANT! Now replace each of the instances of domain with your actual domain.
Save and upload the file and test by going to a non-existing page on your site. You should receive the email right after that.
ImportPassion
06-29-2004, 10:53 PM
couple things with that.
missing the headers to do html mail or something.
the error_start and error_footer will never get appended to the body
58sniper
06-30-2004, 01:22 AM
You are correct. I could have swore I removed the error_start and error_footer stuff before I posted that. I use that for something else.
Also, I've changed some of the hard coded email addresses to the $vboptions['webmasteremail'] variable.
Would it be easier (and allowed) for me to just attach the php file here? It's just the original error page with my stuff added.
Whatever is convenient (and doesn't break the rules).....
AlexanderT
06-30-2004, 06:09 AM
Nice addition, 58sniper!
I'd be only worried to be flooded with e-mails (at least if you have a high traffic site). Although my site is relatively small, for June 2004 I had 3864 404-Document Not-Found-errors, in May even 5048 of these errors. Not because I am sloppy with html programming, but because people (or bots, in majority) were trying to access and spider outdated links.
58sniper
06-30-2004, 11:53 PM
The biggest problem I've seen is the PowerPC version of IE. It apparently has poor support for images in CSS. I think I'm going to filter that.
What's the rule about modifying hacks? Do I just post the new file here or do I need to start a new thread and give props?
I ask because I'd like to switch all of the IF statements to a switch, and make a few more changes, and I think the new version would be beneficial.
Jolten
07-01-2004, 06:47 AM
Great addition. Thanks.
58sniper
07-04-2004, 11:27 PM
Okay - here we go. This is an 'extension' of this hack, which includes:
- Emailing of the webmaster for 404 and 500 errors.
- Changed all of the IF ELSE statements to a single SWITCH
- Used more vBulletin variables so that no code modification is required to implement this.
I've tested this for a couple of days, and haven't seen any problems. Let me know if you spot any.
To install, just drop this in your forum folder, overwriting the original (which, of course, you backed up).
58sniper
07-08-2004, 11:21 PM
Updated with the following changes:
Subject of error email now indicates type of error.
Address of referring page (if it exists) is now a link.
This is a straight drop-in replacement for the above.
This hack was Wrorking With me B4 After We update our Server . it dont work
Can i know what this hack need from me to install any software or anything ..
Thankyou
58sniper
07-18-2004, 10:38 PM
This hack was Wrorking With me B4 After We update our Server . it dont work
Can i know what this hack need from me to install any software or anything ..
Thankyou
What happens?
Slapyo
08-29-2004, 06:28 PM
hmmm, can someone help me out here? here is my .htaccess and my error.php file. error.php is in the root directory along with the .htaccess file. however if you goto some random page the only thing i get to load up is a blank page. nothing is inserted. even if i goto just error.php it is still blank. but according to the code it should atleast give the very last error on the list. it also never actually goes to error.php ... if you want to goto asfdasdf.php that is still in the URL bar ... shouldn't it redirect to the error.php file?
.htaccess:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 401 /error.php
ErrorDocument 500 /error.php
ErrorDocument 503 /error.php
error.php:
<?php
if(isset($_SERVER['REDIRECT_STATUS'])) {
if ($_SERVER['REDIRECT_STATUS']=="404") {
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you believe that the mistake is on our part.";
} elseif ($_SERVER['REDIRECT_STATUS']=="403") {
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you think that there is a mistake.";
} elseif ($_SERVER['REDIRECT_STATUS']=="401") {
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you think that there is a mistake.";
} elseif ($_SERVER['REDIRECT_STATUS']=="500") {
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us to report this problem.";
} elseif ($_SERVER['REDIRECT_STATUS']=="503") {
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
} else {
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
}
} else {
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
}
require_once("header.inc.php");
?>
<p><b><?=$error['title']?></b>
<br /><?=$error['description']?>
<br /><?=$error['contact']?></p>
<?
require_once("footer.inc.php");
?>
58sniper
08-30-2004, 01:07 AM
hmmm, can someone help me out here? here is my .htaccess and my error.php file. error.php is in the root directory along with the .htaccess file. however if you goto some random page the only thing i get to load up is a blank page. nothing is inserted. even if i goto just error.php it is still blank. but according to the code it should atleast give the very last error on the list. it also never actually goes to error.php ... if you want to goto asfdasdf.php that is still in the URL bar ... shouldn't it redirect to the error.php file?
no. The URL will stay the same.
.htaccess:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 401 /error.php
ErrorDocument 500 /error.php
ErrorDocument 503 /error.php
That looks fine
error.php:
<?php
if(isset($_SERVER['REDIRECT_STATUS'])) {
if ($_SERVER['REDIRECT_STATUS']=="404") {
$error['title'] = "404 File Not Found";
$error['description'] = "The web server cannot find the file you asked for. Check the URL to ensure that the path is correct.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you believe that the mistake is on our part.";
} elseif ($_SERVER['REDIRECT_STATUS']=="403") {
$error['title'] = "403 Forbidden";
$error['description'] = "You don't have permission to access this document on this server.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you think that there is a mistake.";
} elseif ($_SERVER['REDIRECT_STATUS']=="401") {
$error['title'] = "401 Unauthorized";
$error['description'] = "The URL you are requesting requires proper authentication.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if you think that there is a mistake.";
} elseif ($_SERVER['REDIRECT_STATUS']=="500") {
$error['title'] = "500 Internal Server Error";
$error['description'] = "We encountered an unexpected condition.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us to report this problem.";
} elseif ($_SERVER['REDIRECT_STATUS']=="503") {
$error['title'] = "503 Service Unavailable";
$error['description'] = "We are currently unable to handle your request due to a temporary overloading or maintenance of the server.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
} else {
$error['title'] = "Unknown Error: " . $_SERVER['REDIRECT_STATUS'];
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
}
} else {
$error['title'] = "Unknown Error";
$error['description'] = "We are currently unable to handle this error.";
$error['contact'] = "Please <a href=\"http://www.veteransresources.org/forums/sendmessage.php\">contact</a> us if this problem persists.";
}
require_once("header.inc.php");
?>
<p><b><?=$error['title']?></b>
<br /><?=$error['description']?>
<br /><?=$error['contact']?></p>
<?
require_once("footer.inc.php");
?>
Well, I can't see what header.inc.php or footer.inc.php include. So I can't really troubleshoot. Did you try just using the originally supplied code?
Slapyo
08-30-2004, 03:05 AM
this is the original code, i just stripped out the part where it gives the redirect stuff. this way i could have it for any page in my site instead of just the forums.
header and footer basically just open the table and close the table. header also includes the menu.
header.inc.php:
<?
ob_start('ob_gzhandler');
chdir("./forums/");
require_once("./global.php");
require_once("./includes/functions_forumlist.php");
chdir("../");
chdir("./chat/");
require_once("./users.php");
chdir("../");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
<meta name="generator" content="vBulletin 3.0.3" />
<meta name="keywords" content="veterans,resources,help,support,vietnam,ptsd,agent orange,cancer,gulf war,iraq,afghanistan" />
<meta name="description" content="This is a discussion forum where veterans help other veterans." />
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="shortcut icon" href="http://www.veteransresources.org/favicon.ico" type="image/x-icon" />
<title>VeteransResources.org</title>
<style type="text/css">
body {
margin: 0px 0px 0px 0px;
background-color: #f0eedb;
}
.black {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #000000;
padding-right: 10px;
padding-left: 10px;
padding-top: 10px;
padding-bottom: 10px;
}
.black a:link, .black a:visited, .black a:active .black a:hover {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #000000;
text-decoration: underline;
}
.white {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #ffffff;
padding-right: 10px;
padding-left: 10px;
}
.white a:link, .white a:visited, .white a:active, .white a:hover {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #ffffff;
text-decoration: none;
}
.loginform {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #000000;
}
.maintable {
height: 100%;
}
</style>
<script language="javascript" type="text/javascript">
<!--
function openchat() {
window.open('http://www.veteransresources.org/chat/member.php','chat','resizable=yes,scrollbars=no,wi dth=650,height=500');
}
//-->
</script>
</head>
<body>
<table width="760" class="maintable" cellspacing="0" cellpadding="0" align="center" border="0">
<tr>
<td width="480" height="30" bgcolor="#2d356e" class="white"><a href="http://www.veteransresources.org">Home</a> | <a href="http://www.veteransresources.org/forums/">Message Board</a> | <? if ($bbuserinfo['userid']!=0) {?><a href="#" onclick="openchat();">Chat (<?=$zznumber?>)</a> | <?}?><a href="http://www.veteransresources.org/links.php">Links</a> | <a href="http://www.veteransresources.org/forums/sendmessage.php">Contact</a></td>
<td width="280" height="30" align="right" bgcolor="#2d356e" class="white"><? echo date("F j, Y"); ?></td>
</tr>
<tr>
<td width="760" height="100" colspan="2"><img src="images/logo.jpg" width="760" height="100" border="0" alt="VeteransResources.org" /></td>
</tr>
<tr>
<td width="760" bgcolor="#ffffff" colspan="2" class="black" valign="top">
footer.inc.php:
</td>
</tr>
<tr>
<td width="480" height="30" bgcolor="#2d356e" class="white"><a href="privacy.php">Privacy Policy</a></td>
<td width="280" height="30" align="right" bgcolor="#2d356e" class="white">Copyright © 2004 VeteransResources.org</td>
</tr>
</table>
</body>
</html>
<?
ob_end_flush();
?>
Slapyo
08-30-2004, 03:08 AM
actually, i just goofed around with the error.php file and if i place the require_once("header.inc.php"); above the error code stuff it works. weird.
58sniper
10-02-2004, 12:31 AM
Here's an update.
I added info to the email sent to the admin. It now indicates the style number for the user that generated the error. Why? Because one of the things that you'll need to know is what the user was attempting to do that triggered a 404 error. But adding the style, we can further track down missing files or incorrect path problems.
I couldn't find a variable that contained the actual style NAME without doing another query. So I just include the style ID number. We can quickly look up which style that corresponds to in the ACP.
Just replace the existing file with this one and let me know what you think.
AlexanderT
10-02-2004, 11:13 AM
I couldn't find a variable that contained the actual style NAME without doing another query. So I just include the style ID number. We can quickly look up which style that corresponds to in the ACP..
Hi 58sniper,
take a look at $datastore['stylecache'], or $stylechoosercache
Jim Mayhugh
01-01-2005, 07:11 PM
If your $error['contact'] message is the same for all errors, you can save some typing by placing it outside of the switch() statement once.
Here's a copy of my file with a few more error codes inserted.
Delphiprogrammi
02-28-2005, 08:55 PM
hi people,
nice hack but it fails to work for me.i have a directory (within my root directory) called "errorpages" i upload error.php and asked my host to allow the "FileInfo" thingy there but i get include errors "Warning: main(./includes/init.php): failed to open stream: No such file or directory " if i add the correct path (eg "../includes/global.php") then vbulletin stop saying that the config file is not there but it is .... what can i do about this ?
Delphiprogrammi
03-01-2005, 01:10 PM
hi,
i've asked my host to configure the "FileInfo" Directory for my httpdocs they replyed they did that (and apache seems to be restarted) however if i go directly to error.php it says "unknown error" (like it should) BUT if you type
www.mysite.com/whateverhere => this doesn't exist so a 404 file not found should come up but all i get is white browser window with the text "error.php" printed in it nothing else ??
htaccess file i use
ErrorDocument 400 error.php
ErrorDocument 401 error.php
ErrorDocument 403 error.php
ErrorDocument 404 error.php
ErrorDocument 500 error.php
the attachment is what internet explorer shows me what to do :confused:
Nice, thank you very much, I was originally going to use this mod (https://vborg.vbsupport.ru/showthread.php?t=66305) but after following the link to this thread, I decided to use this method. To me it was easier and hassle free... again thank you :)
Installed it, it works perfectly. Tres cool. Thanks. :D
ChrisLM2001
04-13-2005, 11:40 PM
Is anyone getting this hack to work in cpanel?
Got the server configured for AllowOverride FileInfo in httpd.conf. But when I go to test if it works, I just get the browser's default error page. The error log shows an error is there, but it refuses to call the error.php file. :(
I put this....
ErrorDocument 403 /forums/error.php
ErrorDocument 404 /forums/error.php
ErrorDocument 401 /forums/error.php
ErrorDocument 500 /forums/error.php
ErrorDocument 503 /forums/error.php
in my /public_html/ directory .htaccess file.
The error.php in the /forums directory.
Created the shell_error file too.
But something is wrong, as I can't get the error.php to show it contents.
Anyone with a workaround?
Chris
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.