10

Is it possible to send an automatic email that includes details about the requested page to the webmaster when a visitors hits a 500 internal server error page?

That way the web master could act more quickly to solve the problem. This is a general question so which platform is used is irrelevant.

1
  • 1
    please add web server software and language you can(want) use. (apache, nginx, iis, php, asp) so people will be able to show you script examples.
    – jflaflamme
    Jan 17, 2012 at 10:10

5 Answers 5

7

Yes, it's possible. You just need to ascertain whether the web server is IIS or Apache and then you can set it to show a custom page (which will contain the code to capture the details you want from the user and e-mail it to you) whenever a 500 error is encountered.

For Apache, for instance, it's really simple. Simply create (or add if one exists) a .htaccess and use the following rule within it to set up your custom error document:

ErrorDocument 500 /error-docs/500.php
2
  • and now for nginx? :)
    – rogerdpack
    Apr 14, 2014 at 14:31
  • 2
    @rogerdpack, error_page
    – Bluebaron
    Aug 10, 2016 at 22:25
7

Sending a mail with every error, via a custom error page, may not work if the problem is with PHP related: your custom page may not run either so the mail doesn't go out. Also you'll get one email per error which could be a flood.

I'd suggest instead implementing some form of log scanning: have a cron job (or scheduled task under Windows) scan the log files for errors every day or every few hours and send a summary of anything found since the last check to the relevant admin(s). You could also make your log checking script do a few other things like make sure the web server service (and any database services and so forth) is running, if only for paranoia's sake. If nothing else, one email per reporting period can cover other HTTP error codes (401, 404, ...) and other things found in the logs. If you do this, always send the email message even if nothing is wrong: that way you know if your scanning script has failed to run because you stop getting messages (otherwise no message could either mean all is well or the damage report machine is damaged).

2
  • Alternatively, you can hook into the logging process directly on Apache by having it write (or pipe) log entries to a perl script or a database which supports hooks and user-defined functions (or is capable of sending email other ways). You can also intercept Apache log events using a custom module. Jan 14, 2012 at 0:42
  • Upvoted, I think your answer really deserve to be upvoted. that's practical solution.
    – Alireza
    Jan 14, 2012 at 7:32
4

Yes, send an email for every error. It's also a good idea to send as much info as you can get as part of the email. Think about grabbing:

  • the contents of the form collection,
  • all session variables,
  • the browser user-agent string,
  • cookie values,
  • the page URL, including any querystring parameters.

This helps greatly for debugging purposes. It's trivial to get this info in classic ASP and ASP.NET via the Request and Session objects.

Just don't have an error on your custom error page, or you'll freak out the web server.

3

Yes, very possible. Except email, you can also check Web Server log.

I suggest don't send email on every single 500, otherwise if theres a bug, you mailbox will get flooded. Just record the error id, send 1 for the same error on same id.

2
  • My take is that recieving a email when something goes wrong makes the life of the webmaster a little easier instead of going through the web server log regualary. Good point about the 1 email idea. Upvote! Jan 10, 2012 at 13:07
  • Thanks. I was use ASP, in old time, the ASP gets an error code, I use it and the url of the page, make a unique key and save to memory, I got 1 email on every error and on every time memory flushed (e.g. app reboot). Not so many email, but enough to track errors. (btw, this way also can track 404, but be careful, these days too much 404 error from bots)
    – Eric Yin
    Jan 10, 2012 at 13:11
-1

You can add an iframe that loads a php from other server, then your error page will always send mails.

1
  • 2
    Why an iframe? Not sure I understand the reason.
    – Andrew
    Sep 17, 2012 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.