Text generated by exception */ public function __construct($exception_message, $error_code = 0) { parent::__construct($exception_message); $this->insertInLogFile($exception_message, $error_code); } /** * @brief Insert data from exceptions in logfile */ public function insertInLogFile($exception_message, $error_code) { $get = null; $post = null; $session = null; $included_files = null; foreach ( $_GET as $key => $value ) { $get .= "\n -> ".escapeshellcmd($key).' : '.$value; } if ( is_null($get) ) $get = 'none'; foreach ( $_POST as $key => $value ) { $post .= "\n -> ".escapeshellcmd($key).' : '.$value; } if ( is_null($post) ) $post = 'none'; $files = get_included_files(); foreach ( $files as $key => $value ) { $included_files .= "\n -> ".$key.' : '.$value; } if ( is_null($included_files) ) $included_files = 'none'; $message = "An error has been generated : \n"; $message .= "Warning : The content is protected, is not the reel content (POST,GET) !\n"; $message .= 'Date : '.date('Y-m-d H:i:s')."\n"; $message .= 'Error : '.$exception_message."\n"; $message .= 'File : '.$this->getFile()."\n"; $message .= 'Line : '.$this->getLine()."\n"; $message .= 'Code : '.$this->getCode()."\n"; if ( isset($_SERVER['HTTP_USER_AGENT']) ) $message .= 'Browser : '.@escapeshellcmd($_SERVER['HTTP_USER_AGENT'])."\n"; $message .= 'IP Address : '.$_SERVER['REMOTE_ADDR']."\n"; $message .= 'Call Page : '.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.@escapeshellcmd($_SERVER['QUERY_STRING'])."\n"; $message .= 'Request method : '.$_SERVER['REQUEST_METHOD']."\n"; $message .= 'Request timer : '.$_SERVER['REQUEST_TIME']."\n"; if ( isset($_SERVER['HTTP_REFERER']) ) $message .= 'Referer : '.@escapeshellcmd($_SERVER['HTTP_REFERER'])."\n"; $message .= 'Script path : '.$_SERVER['SCRIPT_FILENAME']."\n"; $message .= 'GET value : '.$get."\n"; $message .= 'POST value : '.$post."\n"; $message .= 'Included files : '.$included_files."\n"; $message .= "Execution traces : \n".$this->getTraceAsString()."\n"; $message .= "---------------------------------------------------\n"; $message .= "\n\n"; $file_handle = fopen (PATH_LOGS.date('Y-m-d').'.log', 'a+'); if ( !$file_handle ) { mail('root@kelio.org', 'CRITICAL ERROR !!', 'The logfile of exceptions can\'t be open !'); } $file_writen = fwrite ( $file_handle, $message ) ; if ( !$file_writen ) { mail('root@kelio.org', 'CRITICAL ERROR !!', 'The logfile of exception can\'t be written !'); } fclose($file_handle); if ( defined('DEBUG') and (preg_match('`ajax.php`i',$_SERVER['PHP_SELF']) == 0) ) { $unique_id = mt_rand(0,2500); $echo = "
"; $echo .= "An error has been generated :
\n"; $echo .= 'Error : '.nl2br($exception_message)."
\n"; $echo .= 'File : '.$this->getFile()."
\n"; $echo .= 'Line : '.$this->getLine()."
\n"; $echo .= 'Code : '.$error_code."
\n"; $echo .= "Trace :\n".nl2br($this->getTraceAsString())."

\n"; $echo .= "For see complete rapport, clic here
\n"; $echo .= "For quit this error, clic here
\n"; $echo .= "
\n"; $echo .= "
\n\n\n\n"; echo $echo; } } // End of insertInLogFile /** * @brief Display HTML error */ public function displayErrorMessage() { @$page = file_get_contents(PAGE_CRITICAL_ERROR); if ( !$page ) { die(NOLOG_ERROR); } else { echo $page; } die(); } // End of displayErrorMessage /** * @brief Display 'critical_error' for ajax */ public function displayCriticalError() { echo 'critical_error'; die(); } } /** * @brief Manage PHP error */ function myErrorHandler($type, $string, $file, $line, $context){ try { switch ($type) { case E_USER_WARNING: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -999); break; case E_USER_NOTICE: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -998); break; case E_WARNING: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -899); break; case E_NOTICE: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -898); break; case E_ERROR: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -797); break; default: throw new MyException("An PHP error has been generated :\n -> Error : ".$string."\n -> File : ".$file."\n -> Line : ".$line."\n -> Context : ".$context, -797); } } catch ( MyException $oException ) { } } set_error_handler("myErrorHandler"); ?>