From b33aa43e799337dcb94a67b4ebf3e5f2969364b9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Nov 2015 12:13:10 +0100 Subject: [request.inc.php] Add optional parameter to control variable type --- inc/request.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'inc/request.inc.php') diff --git a/inc/request.inc.php b/inc/request.inc.php index bb212dfd..604a2b0e 100644 --- a/inc/request.inc.php +++ b/inc/request.inc.php @@ -12,9 +12,10 @@ class Request * @param string $default Value to return if $_GET does not contain $key * @return mixed Field from $_GET, or $default if not set */ - public static function get($key, $default = false) + public static function get($key, $default = false, $type = false) { if (!isset($_GET[$key])) return $default; + if ($type !== false) settype($_GET[$key], $type); return $_GET[$key]; } @@ -24,9 +25,10 @@ class Request * @param string $default Value to return if $_POST does not contain $key * @return mixed Field from $_POST, or $default if not set */ - public static function post($key, $default = false) + public static function post($key, $default = false, $type = false) { if (!isset($_POST[$key])) return $default; + if ($type !== false) settype($_POST[$key], $type); return $_POST[$key]; } @@ -36,9 +38,10 @@ class Request * @param string $default Value to return if $_REQUEST does not contain $key * @return mixed Field from $_REQUEST, or $default if not set */ - public static function any($key, $default = false) + public static function any($key, $default = false, $type = false) { if (!isset($_REQUEST[$key])) return $default; + if ($type !== false) settype($_REQUEST[$key], $type); return $_REQUEST[$key]; } -- cgit v1.2.3-55-g7522