Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / grab_globals.lib.php
blobaafd1690b44339eb6690489fd942c7a3fa3b4f13
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * This library grabs the names and values of the variables sent or posted to a
5 * script in $_GET, $_POST and $_FILES superglobals and sets simple globals
6 * variables from them. It does the same work for $HTTP_ACCEPT_LANGUAGE and
7 * $HTTP_AUTHORIZATION.
9 * @package phpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * copy values from one array to another, usually from a superglobal into $GLOBALS
18 * @param array $array values from
19 * @param array $target values to
20 * @param boolean $sanitize prevent importing key names in $_import_blacklist
22 function PMA_recursive_extract($array, &$target, $sanitize = true)
24 if (! is_array($array)) {
25 return false;
28 if ($sanitize) {
29 $valid_variables = preg_replace($GLOBALS['_import_blacklist'], '',
30 array_keys($array));
31 $valid_variables = array_unique($valid_variables);
32 } else {
33 $valid_variables = array_keys($array);
36 foreach ($valid_variables as $key) {
38 if (strlen($key) === 0) {
39 continue;
42 if (is_array($array[$key])) {
43 // there could be a variable coming from a cookie of
44 // another application, with the same name as this array
45 unset($target[$key]);
47 PMA_recursive_extract($array[$key], $target[$key], false);
48 } else {
49 $target[$key] = $array[$key];
52 return true;
56 /**
57 * @var array $_import_blacklist variable names that should NEVER be imported
58 * from superglobals
60 $_import_blacklist = array(
61 '/^cfg$/i', // PMA configuration
62 '/^server$/i', // selected server
63 '/^db$/i', // page to display
64 '/^table$/i', // page to display
65 '/^goto$/i', // page to display
66 '/^back$/i', // the page go back
67 '/^lang$/i', // selected language
68 '/^collation_connection$/i', //
69 '/^set_theme$/i', //
70 '/^sql_query$/i', // the query to be executed
71 '/^GLOBALS$/i', // the global scope
72 '/^str.*$/i', // PMA localized strings
73 '/^error_handler.*$/i', // the error handler
74 '/^_.*$/i', // PMA does not use variables starting with _ from extern
75 '/^.*\s+.*$/i', // no whitespaces anywhere
76 '/^[0-9]+.*$/i', // numeric variable names
77 //'/^PMA_.*$/i', // other PMA variables
80 if (! empty($_GET)) {
81 PMA_recursive_extract($_GET, $GLOBALS);
84 if (! empty($_POST)) {
85 PMA_recursive_extract($_POST, $GLOBALS);
88 if (! empty($_FILES)) {
89 $_valid_variables = preg_replace($GLOBALS['_import_blacklist'], '', array_keys($_FILES));
90 foreach ($_valid_variables as $name) {
91 if (strlen($name) != 0) {
92 $$name = $_FILES[$name]['tmp_name'];
93 ${$name . '_name'} = $_FILES[$name]['name'];
96 unset($name, $value);
99 /**
100 * globalize some environment variables
102 $server_vars = array('HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
103 foreach ($server_vars as $current) {
104 // it's not important HOW we detect html tags
105 // it's more important to prevent XSS
106 // so it's not important if we result in an invalid string,
107 // it's even better than a XSS capable string
108 if (PMA_getenv($current) && false === strpos(PMA_getenv($current), '<')) {
109 $$current = PMA_getenv($current);
110 // already imported by register_globals?
111 } elseif (! isset($$current) || false !== strpos($$current, '<')) {
112 $$current = '';
115 unset($server_vars, $current, $_import_blacklist);