Source for file utilINC.php
Documentation is available at utilINC.php
* utilINC.php stores site-wide utility functions
* Stores functions like myerror(), which handles MySQL and other
* or die() errors, myRedirect() to direct users away from pages and
* dbOut() which cleans data coming from MySQL
* @author Bill Newman <williamnewman@gmail.com>
* @version 1.0 2008/05/01
* @link http://www.newmanix.com/itc280/
* @license http://opensource.org/licenses/osl-3.0.php Open Software License ("OSL") v. 3.0
* If TRUE, will show errors on page, instead of making errors private.
* This variable can be over-ridden by $HideAllErrors variable in configINC.php
* @global boolean $HidePageErrors
//END CONFIG AREA ----------------------------------------------------------
* Provides sitewide configuration info and error handling function
require_once("configINC.php");
* Provides database connection capability with conn() function
require_once("connINC.php");
* Prints a customized MySQL (or other die() based) error message
* When 'or die()' is used, we use this function to customize the
* error message sent. The global var $HidePageErrors, if true, shows only a
* public error message, including a code for users to pass identifying the page
* and line number involved for the error.
* The above would be the example for this file, plus an error at line 41
* This allows a user to report an error that identifies it, without compromising site security
* @param string $myfile file name provided by __FILE__ constant
* @param string $myline line number provided by __LINE__ constant
* @param string $errorMsg message provided by MySQL or programmer
function myerror($myFile, $myLine, $errorMsg=
"No error message sent.")
if ($HideAllErrors ||
$HidePageErrors)
{//show errors directly on page. (troubleshooting purposes only!)
print
"Error in file: <b>'$myFile'</b> on line: <font color=\"blue\"><b>$myLine</b></font> ";
print
"Error message: <font color=\"red\"><b>$errorMsg</b></font></body></html>";
}else{//display generic error message, with support email from config file
//instructions and apology for user
* Forcibly passes user to a local URL. Requires ob_start(); at the top of including pages
* PHP does not have a redirect to a local file. The PHP header() function
* requires an absolute URL, eliciting this workaround.
* Any page using myRedirect() needs ob_start() at the top of the page or header() errors will occur.
* Error will say 'headers already sent', etc.
* For completeness, ob_flush() should go at the bottom of the page using myRedirect().
* @param string $myURL locally referenced file as destination for user
{ //passes user to relative URL
$dirName =
dirname($_SERVER['PHP_SELF']);
if($char !=
"/"){$dirName .=
"/";} //only add slash if required!
header("Location: http://" .
$_SERVER['HTTP_HOST'] .
$dirName .
$myURL);
die(); //added for safety!
* Wrapper function for processing data pulled from db
* Forward slashes are added to MySQL data upon entry to prevent SQL errors.
* Using our dbOut() function allows us to encapsulate the most common functions for removing
* slashes with the PHP stripslashes() function, plus the trim() function to remove spaces.
* Later, we can add to this function sitewide, as new requirements or vulnerabilities develop.
* @param string $str data as pulled from MySQL
* @return $str data cleaned of slashes, spaces around string, etc.
if($str!=
""){$str =
stripslashes(trim($str));}//strip out slashes entered for SQL safety
Documentation generated on Sat, 03 May 2008 19:47:45 -0700 by phpDocumentor 1.4.1