doubledee Posted March 17, 2012 Share Posted March 17, 2012 My website is set up so that if there is an error somewhere, I assign an Error Code and redirect the User to a "Results Page" like this... }else{ // Update Failed. $_SESSION['resultsCode'] = 'EMAIL_NEW_EMAIL_FAILED_2129'; }//End of UPDATE EMAIL ADDRESS // Close prepared statement. mysqli_stmt_close($stmt5); // Redirect to Display Outcome. header("Location: " . BASE_URL . "/members/results.php"); // End script. exit(); On the Results Page I display the error in User-friendly wording and usually a corrective action (e.g. "Return to Change E-mail")... // Email Not Changed. case 'EMAIL_NEW_EMAIL_FAILED_2129': echo '<h1>E-mail Change Failed</h1>'; echo '<p>Your e-mail could not be changed due to a System Error.</p>'; echo '<p>Please try again. (2129)</p>'; echo '<a class="button" href="' . BASE_URL . '/members/change_email.php">Change E-mail</a>'; break; When my script is redirected to the Results Page, I would like to log the Error in my database. What kinds of things should I log, and how can I take this not-so-sophisticated error handling code and make it better WITHOUT completely rewriting things?! Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/259132-what-to-log-with-errors/ Share on other sites More sharing options...
darkfreaks Posted March 17, 2012 Share Posted March 17, 2012 for one you could use the heredoc syntax instead of using echo abunch of times like this. case 'EMAIL_NEW_EMAIL_FAILED_2129': $error= <<<EOL <h1>E-mail Change Failed</h1> <p>Your e-mail could not be changed due to a System Error.</p> <p>Please try again. (2129)</p> <a class="button" href="' . BASE_URL . '/members/change_email.php">Change E-mail</a> EOL; echo $error; break; Quote Link to comment https://forums.phpfreaks.com/topic/259132-what-to-log-with-errors/#findComment-1328477 Share on other sites More sharing options...
kicken Posted March 17, 2012 Share Posted March 17, 2012 What you log will depend on what the nature of the error is. For instance, for a DB error you would want to log the query text you are using and any variables your using as parameters for that query. Then you'll be able to re-assemble the query and see what went wrong. If you had an error say opening a file you'd want to log the name of the file being opened, what the error was (permission denied, non-existent, etc), and for good measure maybe the [m=getcwd]current working directory[/m] and [m=get_include_path]include_path setting[/m]. There could be various other types of errors you might have, each will have it's own data that needs logged. Since the information you need to log can vary from error to error you'll need to gather all that information at the time of the error and either pass it to your result script or log the error at that point and just have the result script display the message to the user. Quote Link to comment https://forums.phpfreaks.com/topic/259132-what-to-log-with-errors/#findComment-1328487 Share on other sites More sharing options...
doubledee Posted March 17, 2012 Author Share Posted March 17, 2012 What you log will depend on what the nature of the error is. Sounds like a much more complex topic than I thought. Debbie Quote Link to comment https://forums.phpfreaks.com/topic/259132-what-to-log-with-errors/#findComment-1328490 Share on other sites More sharing options...
RobertP Posted March 18, 2012 Share Posted March 18, 2012 set_error_handler - for all non-fatal errors register_shutdown_function - for fatal errors trigger_error - for your own errors error-level constants - might be helpful Quote Link to comment https://forums.phpfreaks.com/topic/259132-what-to-log-with-errors/#findComment-1328812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.