From d593710fc5d2880f09191ec9225ccb351112f486 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 18 Feb 2015 23:03:23 +0000 Subject: [PATCH 1/3] Updated the way debug=yes in url works to make it visually more appealing --- html/css/styles.css | 3 ++ html/includes/print-debug.php | 89 +++++++++++++++++++++++++++++++++++ html/index.php | 13 +++++ includes/dbFacile.php | 8 +++- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 html/includes/print-debug.php diff --git a/html/css/styles.css b/html/css/styles.css index 0cfcf63287e8..df4e0da6abee 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1628,3 +1628,6 @@ tr.search:nth-child(odd) { font-size: 2.5em; } +.navbar-debug { + min-height: 25px; +} diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php new file mode 100644 index 000000000000..5c23a3536848 --- /dev/null +++ b/html/includes/print-debug.php @@ -0,0 +1,89 @@ + + + + + diff --git a/html/index.php b/html/index.php index d0448a7e4b19..037843a356f6 100755 --- a/html/index.php +++ b/html/index.php @@ -47,6 +47,7 @@ ini_set('display_startup_errors', 1); ini_set('log_errors', 1); ini_set('error_reporting', E_ALL); + set_error_handler('logErrors'); } else { $debug = FALSE; ini_set('display_errors', 0); @@ -55,6 +56,11 @@ ini_set('error_reporting', 0); } +function logErrors($errno, $errstr, $errfile, $errline) { + global $php_debug; + $php_debug[] = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline); +} + foreach ($_GET as $key=>$get_var) { if (strstr($key, "opt")) @@ -330,6 +336,13 @@ function popUp(URL) echo(""); } +if (is_array($sql_debug) && is_array($php_debug)) { + + include_once "includes/print-debug.php"; + +} + ?> + diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 1f98bc1c973e..d6bb7b7399ba 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -22,10 +22,14 @@ * Used by the other _query functions. * */ function dbQuery($sql, $parameters = array()) { - global $fullSql, $debug; + global $fullSql, $debug, $sql_debug; $fullSql = dbMakeQuery($sql, $parameters); if($debug) { - print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); + if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { + print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); + } else { + $sql_debug[] = $fullSql; + } #echo("\nSQL[".$fullSql."] "); } From f836c2b5e3704fe788819234615b03e12e9d70a2 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 18 Feb 2015 23:51:49 +0000 Subject: [PATCH 2/3] Added catching php fatal exceptions --- html/index.php | 54 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/html/index.php b/html/index.php index 037843a356f6..d801561d0509 100755 --- a/html/index.php +++ b/html/index.php @@ -12,6 +12,37 @@ * */ +$_SERVER['PATH_INFO'] = (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['ORIG_PATH_INFO']); + +function logErrors($errno, $errstr, $errfile, $errline) { + global $php_debug; + $php_debug[] = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline); +} + +function catchFatal() { + $last_error = error_get_last(); + if ($last_error['type'] == 1) { + logErrors($last_error['type'],$last_error['message'],$last_error['file'],$last_error['line']); + } +} + +if (strpos($_SERVER['PATH_INFO'], "debug")) +{ + $debug = "1"; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); + set_error_handler('logErrors'); + register_shutdown_function('catchFatal'); +} else { + $debug = FALSE; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); +} + // Set variables $msg_box = array(); @@ -38,29 +69,6 @@ ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -$_SERVER['PATH_INFO'] = (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['ORIG_PATH_INFO']); - -if (strpos($_SERVER['PATH_INFO'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); - set_error_handler('logErrors'); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); -} - -function logErrors($errno, $errstr, $errfile, $errline) { - global $php_debug; - $php_debug[] = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline); -} - foreach ($_GET as $key=>$get_var) { if (strstr($key, "opt")) From 96a5264abd371006c5d338ba55d38b3c5d657d77 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 18 Feb 2015 23:53:51 +0000 Subject: [PATCH 3/3] Actually print last fatal error out --- html/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html/index.php b/html/index.php index d801561d0509..b2cebb6b7ab0 100755 --- a/html/index.php +++ b/html/index.php @@ -22,7 +22,8 @@ function logErrors($errno, $errstr, $errfile, $errline) { function catchFatal() { $last_error = error_get_last(); if ($last_error['type'] == 1) { - logErrors($last_error['type'],$last_error['message'],$last_error['file'],$last_error['line']); + $log_error = array($last_error['type'],$last_error['message'],$last_error['file'],$last_error['line']); + print_r($log_error); } }