function fix_magic_quotes(&$array) { foreach ($array as $k => $val) { if (!is_array($val)) { $array[$k] = stripslashes($val); } else { fix_magic_quotes($array[$k]); } } }
/** * Recursively strip slashes from an array (eg. $_GET). /**/ function &fix_magic_quotes(&$array) { foreach ($array as $key => $val) { if (is_array($val)) { fix_magic_quotes($array[$key]); } else { $array[$key] = stripslashes($val); } } return $array; }
function fix_magic_quotes($var = NULL, $sybase = NULL) { // si $sybase n'est pas spécifié, on regarde la configuration ini if (!isset($sybase)) { $sybase = ini_get('magic_quotes_sybase'); } // si $var n'est pas spécifié, on corrige toutes les variables superglobales if (!isset($var)) { // si les magic_quotes sont activées if (get_magic_quotes_gpc()) { // tableaux superglobaux a corriger $array = array('_REQUEST', '_GET', '_POST', '_COOKIE'); if (substr(PHP_VERSION, 0, 1) <= 4) { // PHP5 semble ne pas changer _ENV et _SERVER array_push($array, '_ENV', '_SERVER'); // les magic_quotes ne changent pas $_SERVER['argv'] $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : NULL; } foreach ($array as $var) { $GLOBALS[$var] = fix_magic_quotes($GLOBALS[$var], $sybase); } if (isset($argv)) { $_SERVER['argv'] = $argv; } // désactive les magic quotes dans ini_set pour que les // scripts qui y sont sensibles fonctionnent ini_set('magic_quotes_gpc', 0); } // idem, pour magic_quotes_sybase if ($sybase) { ini_set('magic_quotes_sybase', 0); } // désactive magic_quotes_runtime set_magic_quotes_runtime(0); return TRUE; } // si $var est un tableau, appel récursif pour corriger chaque élément if (is_array($var)) { foreach ($var as $key => $val) { $var[$key] = fix_magic_quotes($val, $sybase); } return $var; } // si $var est une chaine on utilise la fonction stripslashes, // sauf si les magic_quotes_sybase sont activées, dans ce cas on // remplace les doubles apostrophes par des simples apostrophes if (is_string($var)) { return $sybase ? str_replace('\'\'', '\'', $var) : stripslashes($var); } // sinon rien return $var; }
function &fix_magic_quotes(&$arr) { if (get_magic_quotes_gpc()) { foreach ($arr as $key => $val) { if (is_array($val)) { fix_magic_quotes($arr[$key]); } else { $arr[$key] = stripslashes($val); } } } return $arr; }
# Normalises Magic Quotes function fix_magic_quotes() { // Originally from BalPHP {@link http://www.balupton/projects/balphp} // Authorised by Benjamin Arthur Lupton {@link http://www.balupton.com/} (the copyright holder) // for use and license under the Aloha Editor Contributors Agreement if (ini_get('magic_quotes_gpc')) { $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); ini_set('magic_quotes_gpc', 0); } } # Fix the magic quotes fix_magic_quotes(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Aloha, Textarea!</title> <script> var Aloha = {}; Aloha.settings = { logLevels: {'error': true, 'warn': true, 'info': true, 'debug': true}, errorhandling: false, ribbon: false }; </script>
require_once 'includes/errors.php'; require_once 'includes/errordisplay.php'; // Make sure we're running a new enough version of php if (substr(phpversion(), 0, 3) < 4.3) { trigger_error('You must be running at least php 4.3 to use this program.', FATAL); } // Clean up input data fix_crlfxy($_GET); fix_crlfxy($_POST); if (get_magic_quotes_gpc()) { fix_magic_quotes($_COOKIE); fix_magic_quotes($_ENV); fix_magic_quotes($_GET); fix_magic_quotes($_POST); fix_magic_quotes($_REQUEST); fix_magic_quotes($_SERVER); } // No MySQL libraries installed in PHP if (!function_exists('mysql_connect')) { $Error = "Please install the MySQL libraries for PHP.\n" . 'The package is usually called something like php-mysql.'; require_once 'templates/_error.php'; exit; } // No database connection info defined? if (empty($_SERVER['db_server']) || empty($_SERVER['db_name']) || empty($_SERVER['db_login'])) { $Error = '<p> The database environment variables are not correctly set in the<br /> included .htaccess file. Please read through the comments included<br /> in the file and set up the db_* environment variables correctly. </p> <p>
/** * Resolve some compatibility differences */ private function _initCompatibility() { # Prepare $this->bootstrap('includes'); # Fix magic quotes if (!isset($fix_magic_quotes) || $fix_magic_quotes) { require_once BALPHP_PATH . '/core/functions/_params.funcs.php'; fix_magic_quotes(); } # BalPHP Arrays - Used for YAML Code Below adjust_yaml_inheritance require_once BALPHP_PATH . '/core/functions/_arrays.funcs.php'; }
function fix_magic_quotes(&$arr) { $new = array(); foreach ($arr as $key => $val) { $key = stripslashes($key); if (is_array($val)) { fix_magic_quotes($val); } else { $val = stripslashes($val); } $new[$key] = $val; } $arr = $new; }
function fix_magic_quotes($var = NULL, $sybase = NULL) { // if sybase style quoting isn't specified, use ini setting if (!isset($sybase)) { $sybase = ini_get('magic_quotes_sybase'); } // if no var is specified, fix all affected superglobals if (!isset($var)) { // if magic quotes is enabled if (get_magic_quotes_gpc()) { // workaround because magic_quotes does not change $_SERVER['argv'] $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : NULL; // fix all affected arrays foreach (array('_ENV', '_REQUEST', '_GET', '_POST', '_COOKIE', '_SERVER') as $var) { $GLOBALS[$var] = fix_magic_quotes($GLOBALS[$var], $sybase); } $_SERVER['argv'] = $argv; // turn off magic quotes, this is so scripts which // are sensitive to the setting will work correctly ini_set('magic_quotes_gpc', 0); } // disable magic_quotes_sybase if ($sybase) { ini_set('magic_quotes_sybase', 0); } // disable magic_quotes_runtime set_magic_quotes_runtime(0); return TRUE; } // if var is an array, fix each element if (is_array($var)) { foreach ($var as $key => $val) { $var[$key] = fix_magic_quotes($val, $sybase); } return $var; } // if var is a string, strip slashes if (is_string($var)) { return $sybase ? str_replace('\'\'', '\'', $var) : stripslashes($var); } // otherwise ignore return $var; }