From 7bef57ca7617f01a6eb173fc02108c0cb139be09 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Tue, 11 Jun 2013 08:37:27 +0100 Subject: [PATCH] Hide errors, @session_start and if wrap function Don't display errors, just silently log them Don't produce warnings if we can't session_start due to headers already being sent Test if the mb_detect_encoding function exists before using --- lib/settings.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/settings.php b/lib/settings.php index 98a107a..f9c5915 100644 --- a/lib/settings.php +++ b/lib/settings.php @@ -1,6 +1,6 @@ )); // Start a session if we haven't already -if(!isset($_SESSION)) {session_start();} +if(!isset($_SESSION)) {@session_start();} // Logout if that's the action we're taking if (isset($_GET['logout'])) { @@ -63,18 +63,20 @@ function numClean($var) { // returns a UTF8 based string with any UFT8 BOM removed function toUTF8noBOM($string,$message) { // Attempt to detect encoding - $encType = mb_detect_encoding($string); - // Get rid of any UTF-8 BOM - $string = preg_replace('/\x{EF}\x{BB}\x{BF}/','',$string); - // Test for any bad characters - $teststring = $string; - $teststringBroken = utf8_decode($teststring); - $teststringConverted = iconv("UTF-8", "UTF-8//IGNORE", $teststringBroken); - // If we have a matching length, UTF8 encode it - if ($encType != "ASCII" && strlen($teststringConverted) == strlen($teststringBroken)) { - $string = utf8_encode($string); - if ($message) { - echo ""; + if (function_exists('mb_detect_encoding')) { + $encType = mb_detect_encoding($string); + // Get rid of any UTF-8 BOM + $string = preg_replace('/\x{EF}\x{BB}\x{BF}/','',$string); + // Test for any bad characters + $teststring = $string; + $teststringBroken = utf8_decode($teststring); + $teststringConverted = iconv("UTF-8", "UTF-8//IGNORE", $teststringBroken); + // If we have a matching length, UTF8 encode it + if ($encType != "ASCII" && strlen($teststringConverted) == strlen($teststringBroken)) { + $string = utf8_encode($string); + if ($message) { + echo ""; + } } } return $string;