Location: PHPKode > scripts > rhc class > rhc-class/rhc_error_handling.php
<?php
/*
DB_OBJECT: a php class which handles connecting to a database, querying the db, and fetching results, and freeing results
AUTHOR: Rick Hopkins
DATE: October 3, 2002
UPDATED LAST: October 16, 2002
*/

/********************************************************************************************************************************/
//we will do our own error reporting
error_reporting(0);

//set error handling to the set_php_error() function
set_error_handler("set_php_error");

if (!($GLOBALS["DIE"])){
	$GLOBALS["DIE"] = 0;
	}

	/********************************************************************/
	//function set_php_error() will eventually be used to set up my own php error messages
	function set_php_error($type, $msg, $file, $line)
	{
		//Add a few additional variables for a debugging
		global $HTTP_HOST, $HTTP_USER_AGENT, $REMOTE_ADDR, $REQUEST_URI;
		
		//create array containing different error descriptions
		$error_type = array(1=>"Error", 2=>"Warning",4=>"Parsing Error",8=>"Notice",16=>"Core Error",32=>"Core Warning",64=>"Compile Error", 128=>"Compile Warning",256=>"User Error",512=>"User Warning",1024=>"User Notice");
		
		//construct error message
		$error_string ="------------------------------------------\n";
		$error_string .= "Date:                 ".date("d-m-Y H:i:s", mktime())."\n";
		$error_string .= "Error Type:           $type - $error_type[$type]\n";
		$error_string .= "Error Message:        $msg\n";
		$error_string .= "Script:               $file(line: $line)\n";
		$error_string .= "Host:                 $HTTP_HOST\n";
		$error_string .= "Client:               $HTTP_USER_AGENT\n";
		$error_string .= "Client IP:            $REMOTE_ADDR\n";
		$error_string .= "Request URI:          $REQUEST_URI\n";
		$error_string .= "------------------------------------------\n\n";
		
		//for testing
		//echo $error_string;
		
		//write message to log file (error_log.txt)
		error_log($error_string, 3, "rhc_error_log.txt");
		
		//email me if errors occur & create message to be displayed to user
		if (($type == "2")
		OR ($type == "8")
		OR ($type == "256")
		OR ($type == "512")
		OR ($type == "1024")){
                        $to = hide@address.com
			mail($to, "Page Error Occurred", $error_string);
			print("<font style=\"font-family:Verdana, Arial; font-weight:bold; color:RED; font-size:10px;\"><br>ERROR!<br></font>");
			print("<font style=\"font-family:Verdana, Arial; font-weight:normal; color:#000000; font-size:10px;\">We're sorry, but the page you requested could not be displayed due to an internal error.<br>The error has been recorded and will be fixed as soon as possible.<br><a href=\"javascript:history.back(1)\">Click Here</a> to get back to the last viewed page.<br><br></font>");
			if ($GLOBALS["DIE"] == "1"){
				die("<font style=\"font-family:Verdana, Arial; font-weight:bold; color:RED; font-size:10px;\">ERROR HAS OCCURRED @ line $line of $file</font>\n");
				}
			}
	}
	
	/********************************************************************/

/********************************************************************************************************************************/
?>
Return current item: rhc class