Source for file configINC.php

Documentation is available at configINC.php

  1. <?
  2. /**
  3.  * configINC.php stores site-wide configuration settings & functions
  4.  * 
  5.  * Stores data like support email address, SUPPORTEMAIL
  6.  *  and functions like my_error_handler() which
  7.  *  over-rides the default error handler of PHP.
  8.  *
  9.  *
  10.  * @package ITC280
  11.  * @author Bill Newman <williamnewman@gmail.com>
  12.  * @version 1.0 2008/05/01
  13.  * @link http://www.newmanix.com/itc280/
  14.  * @license http://opensource.org/licenses/osl-3.0.php Open Software License ("OSL") v. 3.0
  15.  * @todo none
  16.  */
  17.  
  18.  
  19. /**
  20.  * email of site support
  21.  */
  22. define('SUPPORTEMAIL''horsey01@example.com');
  23.  
  24. /**
  25.  * If true, will over-ride page specific MyDebug, and make private all errors
  26.  * @global boolean $HideAllErrors 
  27.  */
  28. $HideAllErrors FALSE;
  29. //END CONFIG AREA ----------------------------------------------------------
  30.  
  31. /**
  32.  * Replace default PHP error handler with ours
  33.  */
  34. set_error_handler ('my_error_handler');
  35.  
  36.  
  37. //END SETTINGS AREA --------------------------------------------------------
  38. /**
  39.  * Overrides PHP's default error handler
  40.  *
  41.  * Inherits error info from default handler and allows us to display
  42.  * custom error messages if these global booleans are both true:
  43.  * 1 $HideAllErrors
  44.  * 2 $HidePageErrors
  45.  * The first comes from this file, the second must be in the calling page
  46.  *   
  47.  * @global boolean $HideAllErrors makes private all errors
  48.  * @global boolean $HidePageErrors makes private errors for this instance only
  49.  * @param string $e_number error number provided by PHP error handler
  50.  * @param string $e_message error message provided by PHP error handler
  51.  * @param string $e_file file name provided by PHP error handler
  52.  * @param string $e_line line number of error provided by PHP error handler
  53.  * @param array $e_vars variables present at time of error
  54.  * @return void 
  55.  * @todo error logging, or emailing admin not implemented
  56.  */
  57. function my_error_handler ($e_number$e_message$e_file$e_line$e_vars{
  58.     global $HideAllErrors$HidePageErrors;
  59.     // Build the error message.
  60.     $errorMsg "Error in file: <b>'$e_file'</b> on line: <font color=\"blue\"><b>$e_line</b></font> "
  61.     $errorMsg .= "Error message: <font color=\"red\"><b>$e_message</b></font>\n";
  62.     // Append $e_vars to the $message.
  63.     $errorMsg .= "<br />variables: <font color=\"green\"><b>" print_r ($e_vars1"</b></font><br />\n";
  64.  
  65.     if ($HideAllErrors || $HidePageErrors)
  66.     // Hide the error
  67.         //error_log($errorMsg, 1, SUPPORTEMAIL); // Send email, or post to log here.  Not implemented!
  68.         
  69.         //instructions and apology for user
  70.         printUserError($e_file,$e_line)
  71.           die();
  72.     }else// Troubleshooting.  Show error
  73.         print '<div class="error">' $errorMsg '</div><br />';
  74.     }
  75.  
  76. }
  77.  
  78. /**
  79.  * Create an error code out of the file name and line number of our error
  80.  *
  81.  * Will make upper case, strip out the vowels and create an
  82.  * error of the file name (minus extension & vowels) + "x" + line number of error
  83.  *
  84.  * Example: CNFGNCx41
  85.  * 
  86.  * The above would be the example for this file, plus an error at line 41
  87.  * This allows a user to report an error that identifies it, without compromising site security
  88.  *
  89.  * @uses printUserError()
  90.  * @param string $myfile file name provided by PHP error handler
  91.  * @param string $myline line number of error provided by PHP error handler
  92.  * @return string 
  93.  * @todo none
  94.  */
  95.  
  96. function createErrorCode($myfile,$myline)
  97. {
  98.     $mySlash strrpos($myfile,"/")//find position of last slash in path
  99.     $myfile substr($myfile,$mySlash 1);  //strip off all but file name
  100.     $myfile substr($myfile0strripos($myfile'.'));//remove extension
  101.     $myfile strtoupper($myfile)//change to upper case
  102.     $vowels array("A""E""I""O""U""Y");  //array of vowels to remove
  103.     $myfile str_replace($vowels""$myfile)//remove vowels
  104.     return $myfile "x" $myline;  //CNFGNCx50
  105. }
  106.  
  107. /**
  108.  * Print a customized public error message
  109.  *
  110.  * Will use a custom error code created by calling
  111.  * createErrorCode() function, and display to user
  112.  *
  113.  * Example: CNFGNCx41
  114.  * 
  115.  * The above would be the example for this file, plus an error at line 41
  116.  * This allows a user to report an error that identifies it, without compromising site security
  117.  *  
  118.  * @param string $myfile file name provided by PHP error handler
  119.  * @param string $myline line number of error provided by PHP error handler
  120.  * @return void 
  121.  * @todo none
  122.  */
  123. function printUserError($myfile,$myline)
  124. {
  125.     $ErrorCode createErrorCode($myfile,$myline)//Create error code out of file name & line number
  126.     print '<h2 align="center">Our page has encountered an error!</h2>';
  127.     print '<table align="center" width="50%" style="border:#F00 1px solid;"><tr><td align="center">';
  128.     print 'Please try again, or email support at <b>' SUPPORTEMAIL '</b>,<br /> and let us know you are receiving ';
  129.     print 'the following Error Code: <b>' $ErrorCode '</b><br />';
  130.     print 'This will help us identify the problem, and fix it as quickly as possible.<br />';
  131.     print 'Thank you for your assistance and understanding!<br />';
  132.     print 'Sincerely,<br />Support Staff<br />';
  133.     print '<a href="index.php">Exit</a></td></tr></table>';
  134.     print '</body></html>';
  135.     
  136. }
  137. ?>

Documentation generated on Sat, 03 May 2008 19:47:45 -0700 by phpDocumentor 1.4.1