summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-06-04 21:38:00 +0200
committerDerek Jones <derek.jones@ellislab.com>2008-06-04 21:38:00 +0200
commit144cb5b3c82ff9a25bd4e675385603675e3699d0 (patch)
tree711307272156fdf37bfb4023400220b5a9e5a386 /system/libraries
parentc04f0fc794c503ca957257f29fc6fc2bed7bd6fa (diff)
simplified and refactored input filtering and retrieval
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Input.php129
1 files changed, 32 insertions, 97 deletions
diff --git a/system/libraries/Input.php b/system/libraries/Input.php
index c2c28fb15..b0a39c59f 100644
--- a/system/libraries/Input.php
+++ b/system/libraries/Input.php
@@ -133,32 +133,14 @@ class CI_Input {
}
else
{
- if (is_array($_GET) AND count($_GET) > 0)
- {
- foreach($_GET as $key => $val)
- {
- $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
- }
- }
+ $_GET = $this->_clean_input_data($_GET);
}
// Clean $_POST Data
- if (is_array($_POST) AND count($_POST) > 0)
- {
- foreach($_POST as $key => $val)
- {
- $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
- }
- }
-
+ $_POST = $this->_clean_input_data($_POST);
+
// Clean $_COOKIE Data
- if (is_array($_COOKIE) AND count($_COOKIE) > 0)
- {
- foreach($_COOKIE as $key => $val)
- {
- $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
- }
- }
+ $_COOKIE = $this->_clean_input_data($_COOKIE);
log_message('debug', "Global POST and COOKIE data sanitized");
}
@@ -232,38 +214,46 @@ class CI_Input {
}
// --------------------------------------------------------------------
-
+
/**
- * Fetch an item from the GET array
+ * Fetch from array
*
- * @access public
+ * This is a helper function to retrieve values from global arrays
+ *
+ * @access private
+ * @param array
* @param string
* @param bool
* @return string
*/
- function get($index = '', $xss_clean = FALSE)
+ function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
{
- if ( ! isset($_GET[$index]))
+ if ( ! isset($array[$index]))
{
return FALSE;
}
if ($xss_clean === TRUE)
{
- if (is_array($_GET[$index]))
- {
- foreach($_GET[$index] as $key => $val)
- {
- $_GET[$index][$key] = $this->xss_clean($val);
- }
- }
- else
- {
- return $this->xss_clean($_GET[$index]);
- }
+ return $this->xss_clean($array[$index]);
}
- return $_GET[$index];
+ return $array[$index];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch an item from the GET array
+ *
+ * @access public
+ * @param string
+ * @param bool
+ * @return string
+ */
+ function get($index = '', $xss_clean = FALSE)
+ {
+ return $this->_fetch_from_array($_GET, $index, $xss_clean);
}
// --------------------------------------------------------------------
@@ -278,27 +268,7 @@ class CI_Input {
*/
function post($index = '', $xss_clean = FALSE)
{
- if ( ! isset($_POST[$index]))
- {
- return FALSE;
- }
-
- if ($xss_clean === TRUE)
- {
- if (is_array($_POST[$index]))
- {
- foreach($_POST[$index] as $key => $val)
- {
- $_POST[$index][$key] = $this->xss_clean($val);
- }
- }
- else
- {
- return $this->xss_clean($_POST[$index]);
- }
- }
-
- return $_POST[$index];
+ return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
// --------------------------------------------------------------------
@@ -313,32 +283,7 @@ class CI_Input {
*/
function cookie($index = '', $xss_clean = FALSE)
{
- if ( ! isset($_COOKIE[$index]))
- {
- return FALSE;
- }
-
- if ($xss_clean === TRUE)
- {
- if (is_array($_COOKIE[$index]))
- {
- $cookie = array();
- foreach($_COOKIE[$index] as $key => $val)
- {
- $cookie[$key] = $this->xss_clean($val);
- }
-
- return $cookie;
- }
- else
- {
- return $this->xss_clean($_COOKIE[$index]);
- }
- }
- else
- {
- return $_COOKIE[$index];
- }
+ return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
}
// --------------------------------------------------------------------
@@ -353,17 +298,7 @@ class CI_Input {
*/
function server($index = '', $xss_clean = FALSE)
{
- if ( ! isset($_SERVER[$index]))
- {
- return FALSE;
- }
-
- if ($xss_clean === TRUE)
- {
- return $this->xss_clean($_SERVER[$index]);
- }
-
- return $_SERVER[$index];
+ return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
}
// --------------------------------------------------------------------