Преглед изворни кода

Introduce a new function: check_php_version(4,1,2) which reports if this install
has (e.g.) version 4.1.2 or higher.

Thijs Kinkhorst пре 23 година
родитељ
комит
2133a45cd7
1 измењених фајлова са 23 додато и 12 уклоњено
  1. 23 12
      functions/global.php

+ 23 - 12
functions/global.php

@@ -20,7 +20,7 @@
  * and redirect.php. Patch submitted by Ray Black.
  * 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 $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION;
   global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS,
   global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS,
          $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
          $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
@@ -47,39 +47,50 @@ if (get_magic_quotes_gpc()) {
 
 
 strip_tags($_SERVER['PHP_SELF']);
 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) {
 function sqstripslashes(&$array) {
     foreach ($array as $index=>$value) {
     foreach ($array as $index=>$value) {
-        if (is_array($array["$index"])) {
-            sqstripslashes($array["$index"]);
+        if (is_array($array[$index])) {
+            sqstripslashes($array[$index]);
         }
         }
         else {
         else {
-            $array["$index"] = stripslashes($value);
+            $array[$index] = stripslashes($value);
         }
         }
     }
     }
 }
 }
 
 
 function sqsession_register ($var, $name) {
 function sqsession_register ($var, $name) {
-    if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
+    if ( !check_php_version(4,1) ) {
         global $HTTP_SESSION_VARS;
         global $HTTP_SESSION_VARS;
-        $HTTP_SESSION_VARS["$name"] = $var;
+        $HTTP_SESSION_VARS[$name] = $var;
     }
     }
     else {
     else {
         $_SESSION["$name"] = $var; 
         $_SESSION["$name"] = $var; 
     }
     }
 }
 }
 function sqsession_unregister ($name) {
 function sqsession_unregister ($name) {
-    if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
+    if ( !check_php_version(4,1) ) {
         global $HTTP_SESSION_VARS;
         global $HTTP_SESSION_VARS;
-        unset($HTTP_SESSION_VARS["$name"]);
+        unset($HTTP_SESSION_VARS[$name]);
     }
     }
     else {
     else {
-        unset($_SESSION["$name"]);
+        unset($_SESSION[$name]);
     }
     }
 }
 }
 function sqsession_is_registered ($name) {
 function sqsession_is_registered ($name) {
     $test_name = &$name;
     $test_name = &$name;
     $result = false;
     $result = false;
-    if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
+    if ( !check_php_version(4,1) ) {
         global $HTTP_SESSION_VARS;
         global $HTTP_SESSION_VARS;
         if (isset($HTTP_SESSION_VARS[$test_name])) {
         if (isset($HTTP_SESSION_VARS[$test_name])) {
             $result = true;
             $result = true;
@@ -99,7 +110,7 @@ function sqsession_is_registered ($name) {
  *  (in that order) and register it as a global var.
  *  (in that order) and register it as a global var.
  */
  */
 function sqextractGlobalVar ($name) {
 function sqextractGlobalVar ($name) {
-    if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
+    if ( !check_php_version(4,1) ) {
         global $_SESSION, $_GET, $_POST;
         global $_SESSION, $_GET, $_POST;
     }
     }
     global  $$name;
     global  $$name;
@@ -120,7 +131,7 @@ function sqsession_destroy() {
     /* start session to be able to destroy it later */
     /* start session to be able to destroy it later */
     session_start();	
     session_start();	
 
 
-    if ( (float)substr(PHP_VERSION , 0 , 3) < 4.1) {
+    if ( !check_php_version(4,1) ) {
         global $HTTP_SESSION_VARS;
         global $HTTP_SESSION_VARS;
         $HTTP_SESSION_VARS = array();
         $HTTP_SESSION_VARS = array();
     }
     }