Source for file utilINC.php

Documentation is available at utilINC.php

  1. <?
  2. /**
  3.  * utilINC.php stores site-wide utility functions
  4.  * 
  5.  * Stores functions like myerror(), which handles MySQL and other
  6.  *  or die() errors, myRedirect() to direct users away from pages and
  7.  *  dbOut() which cleans data coming from MySQL
  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.  * If TRUE, will show errors on page, instead of making errors private.
  21.  * This variable can be over-ridden by $HideAllErrors variable in configINC.php
  22.  * @global boolean $HidePageErrors 
  23.  */
  24. $HidePageErrors FALSE
  25. //END CONFIG AREA ---------------------------------------------------------- 
  26.  
  27.  
  28. /**
  29.  * Provides sitewide configuration info and error handling function
  30.  */ 
  31. require_once("configINC.php");
  32.  
  33. /**
  34.  * Provides database connection capability with conn() function
  35.  */
  36. require_once("connINC.php");
  37.  
  38. /**
  39.  * Prints a customized MySQL (or other die() based) error message
  40.  *
  41.  * When 'or die()' is used, we use this function to customize the
  42.  * error message sent.  The global var $HidePageErrors, if true, shows only a
  43.  * public error message, including a code for users to pass identifying the page
  44.  * and line number involved for the error.
  45.  *
  46.  * Example: TLNCx41
  47.  * 
  48.  * The above would be the example for this file, plus an error at line 41
  49.  * This allows a user to report an error that identifies it, without compromising site security
  50.  *  
  51.  * 
  52.  * @param string $myfile file name provided by __FILE__ constant
  53.  * @param string $myline line number provided by __LINE__ constant
  54.  * @param string $errorMsg message provided by MySQL or programmer
  55.  * @return void 
  56.  * @uses printUserError()
  57.  * @todo none
  58.  */
  59. function myerror($myFile$myLine$errorMsg="No error message sent.")
  60. {
  61.     global $HideAllErrors$HidePageErrors//comes from configINC.php & calling page
  62.     if ($HideAllErrors || $HidePageErrors)
  63.     {//show errors directly on page.  (troubleshooting purposes only!)
  64.         print "Error in file: <b>'$myFile'</b> on line: <font color=\"blue\"><b>$myLine</b></font> "
  65.         print "Error message: <font color=\"red\"><b>$errorMsg</b></font></body></html>";
  66.         die();
  67.     }else{//display generic error message, with support email from config file
  68.         //instructions and apology for user
  69.         printUserError($myFile,$myLine)
  70.     }        
  71. }
  72.  
  73. /**
  74.  * Forcibly passes user to a local URL.  Requires ob_start(); at the top of including pages
  75.  *
  76.  * PHP does not have a redirect to a local file.  The PHP header() function
  77.  * requires an absolute URL, eliciting this workaround.
  78.  * Any page using myRedirect() needs ob_start() at the top of the page or header() errors will occur.
  79.  *
  80.  * Error will say 'headers already sent', etc.
  81.  * 
  82.  * For completeness, ob_flush() should go at the bottom of the page using myRedirect().
  83.  * 
  84.  * @param string $myURL locally referenced file as destination for user
  85.  * @return void 
  86.  * @todo none
  87.  */
  88. function myRedirect($myURL)
  89. //passes user to relative URL
  90.     $dirName dirname($_SERVER['PHP_SELF']);
  91.     $char substr($dirName,strlen($dirName1);
  92.     if($char != "/"){$dirName .= "/";//only add slash if required!
  93.     header("Location: http://" $_SERVER['HTTP_HOST'$dirName $myURL);
  94.     die()//added for safety!
  95. }
  96.  
  97. /**
  98.  * Wrapper function for processing data pulled from db
  99.  *
  100.  * Forward slashes are added to MySQL data upon entry to prevent SQL errors.
  101.  * Using our dbOut() function allows us to encapsulate the most common functions for removing
  102.  * slashes with the PHP stripslashes() function, plus the trim() function to remove spaces.
  103.  *
  104.  * Later, we can add to this function sitewide, as new requirements or vulnerabilities develop.
  105.  *
  106.  * @param string $str data as pulled from MySQL
  107.  * @return $str data cleaned of slashes, spaces around string, etc.
  108.  * @todo none
  109.  */
  110. function dbOut($str)
  111. {
  112.     if($str!=""){$str stripslashes(trim($str));}//strip out slashes entered for SQL safety
  113.     return $str;
  114. }
  115. ?>

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