| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * globals.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This includes code to update < 4.1.0 globals to the newer format |
| 10 | * It also has two session register functions that work across various |
| 11 | * php versions. |
| 12 | * |
| 13 | * $Id$ |
| 14 | */ |
| 15 | |
| 16 | |
| 17 | /* convert old-style superglobals to current method |
| 18 | * this is executed if you are running PHP 4.0.x. |
| 19 | * it is run via a require_once directive in validate.php |
| 20 | * and redirect.php. Patch submitted by Ray Black. |
| 21 | */ |
| 22 | |
| 23 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 24 | global $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION; |
| 25 | global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS, |
| 26 | $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS; |
| 27 | $_COOKIE =& $HTTP_COOKIE_VARS; |
| 28 | $_ENV =& $HTTP_ENV_VARS; |
| 29 | $_FILES =& $HTTP_POST_FILES; |
| 30 | $_GET =& $HTTP_GET_VARS; |
| 31 | $_POST =& $HTTP_POST_VARS; |
| 32 | $_SERVER =& $HTTP_SERVER_VARS; |
| 33 | $_SESSION =& $HTTP_SESSION_VARS; |
| 34 | } |
| 35 | |
| 36 | function sqsession_register ($var, $name) { |
| 37 | $rg = ini_get('register_globals'); |
| 38 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) { |
| 39 | global $HTTP_SESSION_VARS; |
| 40 | $HTTP_SESSION_VARS["$name"] = $var; |
| 41 | } |
| 42 | else { |
| 43 | session_register("$name"); |
| 44 | } |
| 45 | } |
| 46 | function sqsession_unregister ($name) { |
| 47 | $rg = ini_get('register_globals'); |
| 48 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 && empty($rg)) { |
| 49 | global $HTTP_SESSION_VARS; |
| 50 | unset($HTTP_SESSION_VARS["$name"]); |
| 51 | } |
| 52 | else { |
| 53 | session_unregister("$name"); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Search for the var $name in $_SESSION, $_POST, $_GET |
| 59 | * (in that order) and register it as a global var. |
| 60 | */ |
| 61 | function sqextractGlobalVar ($name) { |
| 62 | global $_SESSION, $_GET, $_POST, $$name; |
| 63 | |
| 64 | if( isset($_SESSION[$name]) ) { |
| 65 | $$name = $_SESSION[$name]; |
| 66 | } |
| 67 | if( isset($_POST[$name]) ) { |
| 68 | $$name = $_POST[$name]; |
| 69 | } |
| 70 | else if ( isset($_GET[$name]) ) { |
| 71 | $$name = $_GET[$name]; |
| 72 | } |
| 73 | } |
| 74 | ?> |