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