| 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 | /* if running with magic_quotes_gpc then strip the slashes |
| 37 | from POST and GET global arrays */ |
| 38 | |
| 39 | if (get_magic_quotes_gpc()) { |
| 40 | sqstripslashes($_GET); |
| 41 | sqstripslashes($_POST); |
| 42 | } |
| 43 | |
| 44 | /* strip any tags added to the url from PHP_SELF. |
| 45 | This fixes hand crafted url XXS expoits for any |
| 46 | page that uses PHP_SELF as the FORM action */ |
| 47 | |
| 48 | strip_tags($_SERVER['PHP_SELF']); |
| 49 | |
| 50 | function sqstripslashes(&$array) { |
| 51 | foreach ($array as $index=>$value) { |
| 52 | if (is_array($array["$index"])) { |
| 53 | sqstripslashes($array["$index"]); |
| 54 | } |
| 55 | else { |
| 56 | $array["$index"] = stripslashes($value); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function sqsession_register ($var, $name) { |
| 62 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 63 | global $HTTP_SESSION_VARS; |
| 64 | $HTTP_SESSION_VARS["$name"] = $var; |
| 65 | } |
| 66 | else { |
| 67 | $_SESSION["$name"] = $var; |
| 68 | } |
| 69 | } |
| 70 | function sqsession_unregister ($name) { |
| 71 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 72 | global $HTTP_SESSION_VARS; |
| 73 | unset($HTTP_SESSION_VARS["$name"]); |
| 74 | } |
| 75 | else { |
| 76 | unset($_SESSION["$name"]); |
| 77 | } |
| 78 | } |
| 79 | function sqsession_is_registered ($name) { |
| 80 | $test_name = &$name; |
| 81 | $result = false; |
| 82 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 83 | global $HTTP_SESSION_VARS; |
| 84 | if (isset($HTTP_SESSION_VARS[$test_name])) { |
| 85 | $result = true; |
| 86 | } |
| 87 | } |
| 88 | else { |
| 89 | if (isset($_SESSION[$test_name])) { |
| 90 | $result = true; |
| 91 | } |
| 92 | } |
| 93 | return $result; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /** |
| 98 | * Search for the var $name in $_SESSION, $_POST, $_GET |
| 99 | * (in that order) and register it as a global var. |
| 100 | */ |
| 101 | function sqextractGlobalVar ($name) { |
| 102 | if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) { |
| 103 | global $_SESSION, $_GET, $_POST; |
| 104 | } |
| 105 | global $$name; |
| 106 | if( isset($_SESSION[$name]) ) { |
| 107 | $$name = $_SESSION[$name]; |
| 108 | } |
| 109 | if( isset($_POST[$name]) ) { |
| 110 | $$name = $_POST[$name]; |
| 111 | } |
| 112 | else if ( isset($_GET[$name]) ) { |
| 113 | $$name = $_GET[$name]; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | function sqsession_destroy() { |
| 118 | global $base_uri; |
| 119 | |
| 120 | if ( (float)substr(PHP_VERSION , 0 , 3) < 4.1) { |
| 121 | global $HTTP_SESSION_VARS; |
| 122 | $HTTP_SESSION_VARS = array(); |
| 123 | } |
| 124 | else { |
| 125 | $_SESSION = array(); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * now reset cookies to 5 seconds ago to delete from browser |
| 130 | */ |
| 131 | |
| 132 | @session_destroy(); |
| 133 | $cookie_params = session_get_cookie_params(); |
| 134 | setcookie(session_name(), '', time() - 5, $cookie_params['path'], |
| 135 | $cookie_params['domain']); |
| 136 | setcookie('username', '', time() - 5, $base_uri); |
| 137 | setcookie('key', '', time() - 5 , $base_uri); |
| 138 | |
| 139 | } |
| 140 | |
| 141 | ?> |