0

Can anyone tell me how I can create a 500 error to check if my error page, 500.php, is ok? I would like to send e-mail alerts to myself when some types of error occurs, how can I do this?

I read a lot, but didn't find much.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
SunnyOne
  • 197
  • 5
  • 15
  • You are better of monitoring access/error logs with a cronjob. A 500=something is seriously wrong, you shouldn't want to handle that in the webserver itself. – Wrikken Jun 25 '12 at 20:32

5 Answers5

1

You can force it with

header('HTTP/1.1 500 Internal Server Error');

Then on your 500.php page use mail()

Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
  • Nope, `ErrorDocument` settings will NOT be called once control over a page is handed over to PHP, it means PHP is considered responsible for the handling. At least, not in Apache 2.2.22. All this does is send the 500 error header, but `500.php` will not be automagically called. – Wrikken Jun 25 '12 at 20:33
  • Hi, I assume "header('HTTP/1.1 500 Internal Server Error');" should go on top of index page, isn't it ? How do I catch the error in this case ? With E_ERROR ? – SunnyOne Jun 26 '12 at 04:39
1

For the point 2:

 I would to send e-mail alerts to myself when some types of error occurs what track to follow ?

Use Google Webmasters tool:

http://www.google.com/webmasters/

Webmasters tools can help you to detect all the server errors and helps you to optimize your site, is a great tool.

More info:

http://en.wikipedia.org/wiki/Google_Webmaster_Tools
Sangar82
  • 5,070
  • 1
  • 35
  • 52
  • Thanks all for your answsers. Maybe I am asking questions the wrong way. Actually, I provoked a syntax error as I hided it with display_startup_errors off display_errors off html_errors off. Pricay is ok .ok Now what can I do to display a message to the visiter ( the browser only displays a the header+no body+ no footer ) and how can I send myself a mail in this cas ? It would help me understanding this part of security issues . – SunnyOne Jun 26 '12 at 10:21
1

I think the easiest way to trigger and 500 error would be to load an invalid .htaccess file

So create a new directory somewhere where Apache can see it and in that directory upload a file named .htacesss with the following contents:

Redirect

This is invalid syntax since you aren't giving all the required Redirect parameters and will reliably generate a 500 error in my testing.

AllInOne
  • 1,450
  • 2
  • 14
  • 32
  • Hi, I tried the following : in folder error_message, where 401,403,404 and 500.php are, I had an htaccess with "Options -indexes", I added Redirect 301 403.php FileThatDoesNotExists and tried to list the folder through typing www.site.com/error_message in the address bar hoping it would trigger error ... but no result According to you I am doing it wrong ? Thanks – SunnyOne Jun 26 '12 at 09:39
  • You want to trigger the error in a different directory from the one that contains your error messages. If you use the same directory for both the server won't be able to read the error message even if the message has been triggered. So: /some_directory/.htaccess (where the htaccess file just contains one word "Redirect"). Then visit www.example.com/some_directory in your browser. Do you get a 500 error? – AllInOne Jun 26 '12 at 14:13
  • Hi again, I did what you said, but I am so sorry to say ... I did not get a 500 error. – SunnyOne Jun 26 '12 at 19:49
0

How to send an e-mail with php:

if($stuffExploded==true)
{
    $to      = 'nobody@example.com';
    $subject = 'Oh, By the way...';
    $message = 'Stuff exploded on page 64, line 221. Good going.';

    mail($to, $subject, $message);
}
Comatose
  • 11
  • 1
0

If you want to monitor your site, i would suggest to use a service like pingdom (they and many others have free plans). These services also alerts you if the server does not process php any more.

Sascha
  • 937
  • 6
  • 14