Updated documentation.
[openemr.git] / interface / main / myadmin / libraries / grab_globals.lib.php
blobc2b6bcf21fd9da5c226709b0a5b7a1943db313b9
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * This library grabs the names and values of the variables sent or posted to a
8 * script in the $_* arrays and sets simple globals variables from them. It does
9 * the same work for the $PHP_SELF, $HTTP_ACCEPT_LANGUAGE and
10 * $HTTP_AUTHORIZATION variables.
12 * loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
15 function PMA_gpc_extract($array, &$target) {
16 if (!is_array($array)) {
17 return FALSE;
19 $is_magic_quotes = get_magic_quotes_gpc();
20 foreach($array AS $key => $value) {
21 if (is_array($value)) {
22 // there could be a variable coming from a cookie of
23 // another application, with the same name as this array
24 unset($target[$key]);
26 PMA_gpc_extract($value, $target[$key]);
27 } else if ($is_magic_quotes) {
28 $target[$key] = stripslashes($value);
29 } else {
30 $target[$key] = $value;
33 return TRUE;
36 if (!empty($_GET)) {
37 PMA_gpc_extract($_GET, $GLOBALS);
38 } // end if
40 if (!empty($_POST)) {
41 PMA_gpc_extract($_POST, $GLOBALS);
42 } // end if
44 if (!empty($_FILES)) {
45 foreach($_FILES AS $name => $value) {
46 $$name = $value['tmp_name'];
47 ${$name . '_name'} = $value['name'];
49 } // end if
51 if (!empty($_SERVER)) {
52 $server_vars = array('PHP_SELF', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
53 foreach ($server_vars as $current) {
54 if (isset($_SERVER[$current])) {
55 $$current = $_SERVER[$current];
56 } elseif (!isset($$current)) {
57 $$current = '';
60 unset($server_vars, $current);
61 } // end if
63 // Security fix: disallow accessing serious server files via "?goto="
64 if (isset($goto) && strpos(' ' . $goto, '/') > 0 && substr($goto, 0, 2) != './') {
65 unset($goto);
66 } // end if