From 9697c5ab0c554015e7ac3e0fe05e52721ec11d6a Mon Sep 17 00:00:00 2001 From: kink Date: Tue, 29 Oct 2002 16:57:55 +0000 Subject: [PATCH] Introduce a new function: check_php_version(4,1,2) which reports if this install has (e.g.) version 4.1.2 or higher. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4060 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/global.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/functions/global.php b/functions/global.php index 6b7e39e6..70adfdf2 100644 --- a/functions/global.php +++ b/functions/global.php @@ -20,7 +20,7 @@ * and redirect.php. Patch submitted by Ray Black. */ -if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { +if ( !check_php_version(4,1) ) { global $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION; global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS; @@ -47,39 +47,50 @@ if (get_magic_quotes_gpc()) { strip_tags($_SERVER['PHP_SELF']); +/* returns true if current php version is at mimimum a.b.c */ +function check_php_version ($a = '0', $b = '0', $c = '0') +{ + global $SQ_PHP_VERSION; + + if(!isset($SQ_PHP_VERSION)) + $SQ_PHP_VERSION = str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'); + + return $SQ_PHP_VERSION >= ($a.$b.$c); +} + function sqstripslashes(&$array) { foreach ($array as $index=>$value) { - if (is_array($array["$index"])) { - sqstripslashes($array["$index"]); + if (is_array($array[$index])) { + sqstripslashes($array[$index]); } else { - $array["$index"] = stripslashes($value); + $array[$index] = stripslashes($value); } } } function sqsession_register ($var, $name) { - if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + if ( !check_php_version(4,1) ) { global $HTTP_SESSION_VARS; - $HTTP_SESSION_VARS["$name"] = $var; + $HTTP_SESSION_VARS[$name] = $var; } else { $_SESSION["$name"] = $var; } } function sqsession_unregister ($name) { - if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + if ( !check_php_version(4,1) ) { global $HTTP_SESSION_VARS; - unset($HTTP_SESSION_VARS["$name"]); + unset($HTTP_SESSION_VARS[$name]); } else { - unset($_SESSION["$name"]); + unset($_SESSION[$name]); } } function sqsession_is_registered ($name) { $test_name = &$name; $result = false; - if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + if ( !check_php_version(4,1) ) { global $HTTP_SESSION_VARS; if (isset($HTTP_SESSION_VARS[$test_name])) { $result = true; @@ -99,7 +110,7 @@ function sqsession_is_registered ($name) { * (in that order) and register it as a global var. */ function sqextractGlobalVar ($name) { - if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { + if ( !check_php_version(4,1) ) { global $_SESSION, $_GET, $_POST; } global $$name; @@ -120,7 +131,7 @@ function sqsession_destroy() { /* start session to be able to destroy it later */ session_start(); - if ( (float)substr(PHP_VERSION , 0 , 3) < 4.1) { + if ( !check_php_version(4,1) ) { global $HTTP_SESSION_VARS; $HTTP_SESSION_VARS = array(); } -- 2.25.1