From be35eacfb33078f0388bc7a478acb31f23760d18 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 28 Sep 2004 15:27:08 +0000 Subject: [PATCH] Added new function parameter(). Eventually this will replace all the optional_variable and require_variable calls anyway, but it's needed in STABLE to fix some security issues. See bug 1865. --- lib/moodlelib.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index cd6ecaf589f..7a7ee3f74bb 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -57,6 +57,20 @@ function optional_variable(&$var, $default=0) { } } +function parameter($varname, $default=NULL) { +/// This function will replace both of the above two functions over time. +/// It returns a value for a given variable name. + + if (isset($_POST[$varname])) { // POST has precedence + return $_POST[$varname]; + } + + if (isset($_GET[$varname])) { + return $_GET[$varname]; + } + + return $default; +} function set_config($name, $value) { /// No need for get_config because they are usually always available in $CFG