|
-
Feb 16th, 2010, 12:35 AM
#1
Thread Starter
Fanatic Member
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.
-
Feb 16th, 2010, 02:19 AM
#2
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.
-
Feb 16th, 2010, 05:14 AM
#3
Thread Starter
Fanatic Member
Re: PHP Error Handling
Ya i meant for runtime errors only. Ya normally on a real websites how are they handling errros?
-
Feb 16th, 2010, 05:28 AM
#4
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:
error_reporting(0); @ini_set('display_errors', 0);
http://www.lost-in-code.com/platform...oduction-site/
-
Feb 16th, 2010, 08:43 PM
#5
Re: PHP Error Handling
I recommend using global error handler and global exception handler functions to catch runtime errors in a production environment.
-
Feb 25th, 2010, 11:07 PM
#6
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).
-
Feb 25th, 2010, 11:25 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|