diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 356f8fec02..425e1f974a 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -521,25 +521,13 @@ if ($token_mismatch) { * current selected database * @global string $GLOBALS['db'] */ -$GLOBALS['db'] = ''; -if (PMA_isValid($_REQUEST['db'])) { - // can we strip tags from this? - // only \ and / is not allowed in db names for MySQL - $GLOBALS['db'] = $_REQUEST['db']; - $GLOBALS['url_params']['db'] = $GLOBALS['db']; -} +PMA_setGlobalDbOrTable('db'); /** * current selected table * @global string $GLOBALS['table'] */ -$GLOBALS['table'] = ''; -if (PMA_isValid($_REQUEST['table'])) { - // can we strip tags from this? - // only \ and / is not allowed in table names for MySQL - $GLOBALS['table'] = $_REQUEST['table']; - $GLOBALS['url_params']['table'] = $GLOBALS['table']; -} +PMA_setGlobalDbOrTable('table'); /** * Store currently selected recent table. diff --git a/libraries/core.lib.php b/libraries/core.lib.php index e7915c2c01..210d3294c4 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -1029,4 +1029,22 @@ function PMA_setPostAsGlobal($post_patterns) } } } + +/** + * Creates some globals from $_REQUEST + * + * @param string $param db|table + * + * @return void + */ +function PMA_setGlobalDbOrTable($param) +{ + $GLOBALS[$param] = ''; + if (PMA_isValid($_REQUEST[$param])) { + // can we strip tags from this? + // only \ and / is not allowed in db names for MySQL + $GLOBALS[$param] = $_REQUEST[$param]; + $GLOBALS['url_params'][$param] = $GLOBALS[$param]; + } +} ?>