banacan Posted November 15, 2011 Share Posted November 15, 2011 I have a site that uses config.inc.php, script 2.1 which has the error handler, my_error_handler. It has worked beautifully for me on many sites over the years but now I have a problem. My client has asked me to use a calendar script on the site, the script is EasyPHPCalendar. The problem is this script creates so many errors that my email box fills up - it causes 133 email error messages to be sent each time a page is loaded. Most of the errors are "undefined variables" or "use of undefined constant", there are also "undefined index" and "constant already defined" errors. My question is how can I continue to use my_error_handler on this site without generating this plethora of errors? Right now I have commented out set_error_handler('my_error_handler') to avoid this problem. The server php.ini file sets the error reporting to E_ALL & ~E_NOTICE, the calendar script also has this: error_reporting(E_ALL ^ E_NOTICE); Why am I getting these notices and how can I adjust the config.inc.php script to prevent this? Many thanks. Link to comment Share on other sites More sharing options...
Jonathon Posted November 15, 2011 Share Posted November 15, 2011 If the calendar script is only used in one page or a few, reference the URLs of those pages in an array and check inside the config file whether you are on that page then if you are on a calendar script page then don't invoke the custom error handler. Not ideal but would at least stop the dreaded emails, I hate it when i get 5 or 6 saying you messed up. Let alone 133 1 Link to comment Share on other sites More sharing options...
banacan Posted November 15, 2011 Author Share Posted November 15, 2011 Thanks for the suggestion Jonathan. Unfortunately the client wants to have a short list of events in the sidebar of every page, so that work-around won't do. Thanks for responding though. Link to comment Share on other sites More sharing options...
Jonathon Posted November 15, 2011 Share Posted November 15, 2011 Well if yours is similar to mine function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { Can't you run a check to see the file that it came from? Wouldn't all the errors be from the same file? i.e calander.php (or whatever it is) regardless of the page? 1 Link to comment Share on other sites More sharing options...
banacan Posted November 16, 2011 Author Share Posted November 16, 2011 Hey Jonathan, I checked through the 133 error message emails and there are many different files responsible for the errors. However, the calendar script is all contained in one sub-directory, so do you think there is a way to exclude any errors created by files within a certain directory? Thanks for helping. Link to comment Share on other sites More sharing options...
Jonathon Posted November 16, 2011 Share Posted November 16, 2011 I'm sure the path of the file is returned in the error message, so maybe use a regex or substring inside an if to tell if the file came from that sub directory and if it did, don't invoke it? 1 Link to comment Share on other sites More sharing options...
banacan Posted November 16, 2011 Author Share Posted November 16, 2011 Well that works great. Here's what I have: // Create the error handler. function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { global $debug, $contact_email; // Don't display errors found if $findme is in $e_file $findme = '/calendar/'; $found = strpos($e_file, $findme); if ($found === false) { // Build the error message. $message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />"; //define timezone ini_set('date.timezone', 'America/Chicago'); // Add the date and time. $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />"; // Append $e_vars to the $message. $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />"; if ($debug) { // Show the error. echo '<p class="error">' . $message . '</p>'; } else { // Log the error: error_log ($message, 1, $contact_email); // Send email. // Only print an error message if the error isn't a notice or strict. if ( ($e_number != E_NOTICE) && ($e_number < 2048)) { echo '<p class="error">A system error occurred. We apologize for the inconvenience.</p>'; } } // End of $debug IF. } // End of $found IF. } // End of my_error_handler() definition. I tested it to make sure that only those messages which are generated by a file with "/calendar/" in the string are excluded. Done. Thanks for your suggestion. Link to comment Share on other sites More sharing options...
Jonathon Posted November 16, 2011 Share Posted November 16, 2011 No problem, glad it works for you. 1 Link to comment Share on other sites More sharing options...
Recommended Posts