f740c049 |
1 | <?php |
2 | /** |
3 | ** validate.php |
4 | ** |
5 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | ** |
8 | ** $Id$ |
9 | **/ |
10 | |
11 | if (defined ('validate_php')) { |
12 | return; |
13 | } else { |
14 | define ('validate_php', true); |
15 | } |
16 | |
17 | session_start(); |
18 | include ("../functions/auth.php"); |
19 | is_logged_in(); |
20 | |
21 | |
22 | // Remove all slashes for form values |
23 | if (get_magic_quotes_gpc()) |
24 | { |
25 | global $REQUEST_METHOD; |
26 | if ($REQUEST_METHOD == "POST") |
27 | { |
28 | global $HTTP_POST_VARS; |
29 | RemoveSlashes($HTTP_POST_VARS); |
30 | } |
31 | elseif ($REQUEST_METHOD == "GET") |
32 | { |
33 | global $HTTP_GET_VARS; |
34 | RemoveSlashes($HTTP_GET_VARS); |
35 | } |
36 | } |
37 | |
38 | // Auto-detection |
39 | // |
40 | // if $send (the form button's name) contains "\n" as the first char |
41 | // and the script is compose.php, then trim everything. Otherwise, |
42 | // we don't have to worry. |
43 | // |
44 | // This is for a RedHat package bug and a Konqueror (pre 2.1.1?) bug |
45 | global $send, $PHP_SELF; |
46 | if (isset($send) && substr($send, 0, 1) == "\n" && |
47 | substr($PHP_SELF, -12) == '/compose.php') |
48 | { |
49 | if ($REQUEST_METHOD == "POST") { |
50 | global $HTTP_POST_VARS; |
51 | TrimArray($HTTP_POST_VARS); |
52 | } else { |
53 | global $HTTP_GET_VARS; |
54 | TrimArray($HTTP_GET_VARS); |
55 | } |
56 | } |
57 | |
58 | //************************************************************************** |
59 | // Trims every element in the array |
60 | //************************************************************************** |
61 | function TrimArray(&$array) { |
62 | foreach ($array as $k => $v) { |
63 | global $$k; |
64 | if (is_array($$k)) { |
65 | foreach ($$k as $k2 => $v2) { |
66 | $$k[$k2] = substr($v2, 1); |
67 | } |
68 | } else { |
69 | $$k = substr($v, 1); |
70 | } |
71 | // Re-assign back to array |
72 | $array[$k] = $$k; |
73 | } |
74 | } |
75 | |
76 | |
77 | //************************************************************************** |
78 | // Removes slashes from every element in the array |
79 | //************************************************************************** |
80 | function RemoveSlashes(&$array) |
81 | { |
82 | foreach ($array as $k => $v) |
83 | { |
84 | global $$k; |
85 | if (is_array($$k)) |
86 | { |
87 | foreach ($$k as $k2 => $v2) |
88 | { |
89 | $newArray[stripslashes($k2)] = stripslashes($v2); |
90 | } |
91 | $$k = $newArray; |
92 | } |
93 | else |
94 | { |
95 | $$k = stripslashes($v); |
96 | } |
97 | // Re-assign back to the array |
98 | $array[$k] = $$k; |
99 | } |
100 | } |
101 | |
102 | ?> |