61d9ec71 |
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 |
242342d0 |
10 | * It also has some session register functions that work across various |
61d9ec71 |
11 | * php versions. |
12 | * |
242342d0 |
13 | * $Id$ |
61d9ec71 |
14 | */ |
15 | |
5f660901 |
16 | # If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways. |
17 | # Force magic_quotes_runtime off. |
18 | # chilts@birdbrained.org - I put it here in the hopes that all SM code includes this. |
19 | # If there's a better place, please let me know. |
20 | ini_set('magic_quotes_runtime','0'); |
61d9ec71 |
21 | |
22 | /* convert old-style superglobals to current method |
23 | * this is executed if you are running PHP 4.0.x. |
24 | * it is run via a require_once directive in validate.php |
25 | * and redirect.php. Patch submitted by Ray Black. |
26 | */ |
27 | |
9697c5ab |
28 | if ( !check_php_version(4,1) ) { |
61d9ec71 |
29 | global $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION; |
30 | global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS, |
31 | $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS; |
32 | $_COOKIE =& $HTTP_COOKIE_VARS; |
33 | $_ENV =& $HTTP_ENV_VARS; |
34 | $_FILES =& $HTTP_POST_FILES; |
35 | $_GET =& $HTTP_GET_VARS; |
36 | $_POST =& $HTTP_POST_VARS; |
37 | $_SERVER =& $HTTP_SERVER_VARS; |
38 | $_SESSION =& $HTTP_SESSION_VARS; |
39 | } |
40 | |
180239ca |
41 | /* if running with magic_quotes_gpc then strip the slashes |
a32985a5 |
42 | from POST and GET global arrays */ |
43 | |
44 | if (get_magic_quotes_gpc()) { |
180239ca |
45 | sqstripslashes($_GET); |
46 | sqstripslashes($_POST); |
a32985a5 |
47 | } |
48 | |
49 | /* strip any tags added to the url from PHP_SELF. |
50 | This fixes hand crafted url XXS expoits for any |
51 | page that uses PHP_SELF as the FORM action */ |
52 | |
53 | strip_tags($_SERVER['PHP_SELF']); |
54 | |
9697c5ab |
55 | /* returns true if current php version is at mimimum a.b.c */ |
56 | function check_php_version ($a = '0', $b = '0', $c = '0') |
57 | { |
3aa17cf9 |
58 | global $SQ_PHP_VERSION; |
9697c5ab |
59 | |
3aa17cf9 |
60 | if(!isset($SQ_PHP_VERSION)) |
5123154f |
61 | $SQ_PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3); |
9697c5ab |
62 | |
3aa17cf9 |
63 | return $SQ_PHP_VERSION >= ($a.$b.$c); |
9697c5ab |
64 | } |
65 | |
3aa17cf9 |
66 | /* recursively strip slashes from the values of an array */ |
a32985a5 |
67 | function sqstripslashes(&$array) { |
3aa17cf9 |
68 | if(count($array) > 0) { |
69 | foreach ($array as $index=>$value) { |
70 | if (is_array($array[$index])) { |
71 | sqstripslashes($array[$index]); |
72 | } |
73 | else { |
74 | $array[$index] = stripslashes($value); |
75 | } |
a32985a5 |
76 | } |
77 | } |
78 | } |
79 | |
61d9ec71 |
80 | function sqsession_register ($var, $name) { |
9697c5ab |
81 | if ( !check_php_version(4,1) ) { |
61d9ec71 |
82 | global $HTTP_SESSION_VARS; |
9697c5ab |
83 | $HTTP_SESSION_VARS[$name] = $var; |
61d9ec71 |
84 | } |
85 | else { |
d7c82551 |
86 | $_SESSION["$name"] = $var; |
61d9ec71 |
87 | } |
3658a999 |
88 | session_register("$name"); |
61d9ec71 |
89 | } |
3aa17cf9 |
90 | |
61d9ec71 |
91 | function sqsession_unregister ($name) { |
9697c5ab |
92 | if ( !check_php_version(4,1) ) { |
d7c82551 |
93 | global $HTTP_SESSION_VARS; |
9697c5ab |
94 | unset($HTTP_SESSION_VARS[$name]); |
61d9ec71 |
95 | } |
96 | else { |
9697c5ab |
97 | unset($_SESSION[$name]); |
61d9ec71 |
98 | } |
3658a999 |
99 | session_unregister("$name"); |
61d9ec71 |
100 | } |
3aa17cf9 |
101 | |
d7c82551 |
102 | function sqsession_is_registered ($name) { |
103 | $test_name = &$name; |
104 | $result = false; |
9697c5ab |
105 | if ( !check_php_version(4,1) ) { |
d7c82551 |
106 | global $HTTP_SESSION_VARS; |
107 | if (isset($HTTP_SESSION_VARS[$test_name])) { |
108 | $result = true; |
109 | } |
110 | } |
111 | else { |
112 | if (isset($_SESSION[$test_name])) { |
113 | $result = true; |
114 | } |
115 | } |
116 | return $result; |
117 | } |
118 | |
61d9ec71 |
119 | |
120 | /** |
121 | * Search for the var $name in $_SESSION, $_POST, $_GET |
122 | * (in that order) and register it as a global var. |
123 | */ |
124 | function sqextractGlobalVar ($name) { |
9697c5ab |
125 | if ( !check_php_version(4,1) ) { |
a32985a5 |
126 | global $_SESSION, $_GET, $_POST; |
127 | } |
128 | global $$name; |
61d9ec71 |
129 | if( isset($_SESSION[$name]) ) { |
130 | $$name = $_SESSION[$name]; |
131 | } |
132 | if( isset($_POST[$name]) ) { |
133 | $$name = $_POST[$name]; |
134 | } |
135 | else if ( isset($_GET[$name]) ) { |
136 | $$name = $_GET[$name]; |
137 | } |
138 | } |
513db22c |
139 | |
140 | function sqsession_destroy() { |
242342d0 |
141 | global $base_uri; |
142 | |
143 | /* start session to be able to destroy it later */ |
144 | session_start(); |
145 | |
9697c5ab |
146 | if ( !check_php_version(4,1) ) { |
242342d0 |
147 | global $HTTP_SESSION_VARS; |
148 | $HTTP_SESSION_VARS = array(); |
149 | } |
150 | else { |
151 | $_SESSION = array(); |
152 | } |
153 | |
154 | /* |
155 | * now reset cookies to 5 seconds ago to delete from browser |
156 | */ |
157 | |
158 | @session_destroy(); |
159 | $cookie_params = session_get_cookie_params(); |
160 | setcookie(session_name(), '', time() - 5, $cookie_params['path'], |
161 | $cookie_params['domain']); |
162 | setcookie('username', '', time() - 5, $base_uri); |
163 | setcookie('key', '', time() - 5 , $base_uri); |
513db22c |
164 | } |
165 | |
61d9ec71 |
166 | ?> |