Is this possible: having PHP email you any time a visitor gets a PHP error?

Discussion in 'PHP' started by Glowing Face Man, Apr 10, 2010.

  1. #1
    I really want PHP to email me *any time that a visitor is served an error message*.

    It's useless for my visitors to see an error message... they cannot fix my scripts... only I can do that... but I can't if I don't know they are there! :mad:

    So... is it possible? Thanks in advance for helping :);)
     
    Glowing Face Man, Apr 10, 2010 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You should not display errors to visitors, the error display is mainly for development purposes.
    http://www.google.com/search?q=hide+php+errors

    You want to receive emails...Technically you can do it but I think your inbox will be filled in no time, you'd rather check your error logs from times to time for weird errors.
     
    nabil_kadimi, Apr 11, 2010 IP
  3. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #3
    If you are on cPanel you can easily check the Error Log.
    Error Log shows the last 300 error messages in reverse order with the time, IP address of the visitor and the URL that caused the error.
    It can be useful for de-bugging scripts you are testing, seeing if you have any missing files or broken links and for seeing if people are trying to cause mischief on your account!
     
    nimonogi, Apr 11, 2010 IP
  4. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Yes, it is.

    You will need to look into using your own custom error handler which is not as hard as it might sound.

    http://uk3.php.net/manual/en/function.set-error-handler.php

    Basically, you can use this to filter errors on their error level or other such criteria and in your customer handler have it send an email to you. This will save you trawling through your logs!

    This may also be of interest to you, if you are not familiar with creating your own handler;
    http://www.w3schools.com/php/php_error.asp
     
    lukeg32, Apr 11, 2010 IP
  5. Glowing Face Man

    Glowing Face Man Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a lot for the help :)

    I'll look into which is easier: building my own error handling like you suggested, or making a cron job to buzz me any time the errorlog changes.
     
    Glowing Face Man, Apr 11, 2010 IP
  6. David3

    David3 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    For me, I'd like to know IMMEDIATELY when there are errors! Nothing's worse than just checking out your own website for fun before you go to bed, and seeing a glaring error! And then wondering how long that's been going on for!
     
    David3, Apr 11, 2010 IP
  7. zerophean

    zerophean Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you got an error on script, you'll get file on your hosting server named "error_log".
     
    zerophean, Apr 11, 2010 IP