Results 1 to 7 of 7

Thread: PHP Error Handling

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    PHP Error Handling

    Which is the best method for error handling, and really used one while building secured websites?
    Whenever the error occured, it must be shown to the users, and must resume the next process.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Error Handling

    uhh. it really depends on the way you're implementing your website and what errors you're talking about.

    if you're talking about custom errors (for example, when a user enters an incorrect username or password), you could simply have an array named $errors that kept track of any errors that occurred. that is, of course, pretty much the absolute simplest way of doing it -- but it might fit with how you're doing things given your knowledge of the language.

    if you're talking about run-time errors, however, then you should be fixing the bugs and programming defensively so that these errors do not occur, rather than trying to display them to the user.

    try to be a bit more specific.

  3. #3

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: PHP Error Handling

    Ya i meant for runtime errors only. Ya normally on a real websites how are they handling errros?

  4. #4
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: PHP Error Handling

    Like kows said you should really be programming defensively so you do not get any runtime errors (notices, warnings + errors).

    You should never display these to your user, it could reveal a flaw in your system and allow them to take advantage of it.

    php Code:
    1. error_reporting(0);
    2. @ini_set('display_errors', 0);

    http://www.lost-in-code.com/platform...oduction-site/

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Error Handling

    I recommend using global error handler and global exception handler functions to catch runtime errors in a production environment.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Error Handling

    Is there a way to capture the error, and have it emailed to yourself, instead of being shown to the user? Like some function you can use that is similar to mysql_error()?

    It seems like a good idea to either have the error messaged emailed to the webmaster, with all the page and connection details so they can evaluate it, or have them stored in a table (assuming there is some kind of admin backend).

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Error Handling

    Use one or both of the functions I suggested, and write some code to send the email in there.

    (Aside: If your error handling function throws an error itself, the default error handler is used.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width