96e2dcf8c73882e735680ef9d18c63d3d81770ea
[squirrelmail.git] / src / validate.php
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 define ('validate_php', true);
14
15 session_start();
16 require_once('../functions/i18n.php');
17 require_once('../functions/auth.php');
18
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 // Everyone needs stuff from config, and config needs stuff from
103 // strings.php, so include them both here.
104 // Include them down here instead of at the top so that all config
105 // variables overwrite any passed in variables (for security)
106 require_once('../functions/strings.php');
107 require_once('../config/config.php');
108 require_once('../src/load_prefs.php');
109 require_once('../functions/page_header.php');
110 require_once('../functions/prefs.php');
111
112 // Set up the language
113 // i18n.php was included by auth.php
114 global $username, $data_dir;
115 set_up_language(getPref($data_dir, $username, 'language'));
116 ?>