Merge pull request #428 from appleboy/input

Fixed core input class 
diff --git a/system/core/Input.php b/system/core/Input.php
index 0dc2c45..f39371f 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -110,13 +110,13 @@
 	 *
 	 * This is a helper function to retrieve values from global arrays
 	 *
-	 * @access	private
+	 * @access	protected
 	 * @param	array
 	 * @param	string
 	 * @param	bool
 	 * @return	string
 	 */
-	function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
+	protected function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
 	{
 		if ( ! isset($array[$index]))
 		{
@@ -141,7 +141,7 @@
 	* @param	bool
 	* @return	string
 	*/
-	function get($index = NULL, $xss_clean = FALSE)
+	public function get($index = NULL, $xss_clean = FALSE)
 	{
 		// Check if a field has been provided
 		if ($index === NULL AND ! empty($_GET))
@@ -169,7 +169,7 @@
 	* @param	bool
 	* @return	string
 	*/
-	function post($index = NULL, $xss_clean = FALSE)
+	public function post($index = NULL, $xss_clean = FALSE)
 	{
 		// Check if a field has been provided
 		if ($index === NULL AND ! empty($_POST))
@@ -198,7 +198,7 @@
 	* @param	bool	XSS cleaning
 	* @return	string
 	*/
-	function get_post($index = '', $xss_clean = FALSE)
+	public function get_post($index = '', $xss_clean = FALSE)
 	{
 		if ( ! isset($_POST[$index]) )
 		{
@@ -220,7 +220,7 @@
 	* @param	bool
 	* @return	string
 	*/
-	function cookie($index = '', $xss_clean = FALSE)
+	public function cookie($index = '', $xss_clean = FALSE)
 	{
 		return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
 	}
@@ -243,7 +243,7 @@
 	* @param	bool	true makes the cookie secure
 	* @return	void
 	*/
-	function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
+	public function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
 	{
 		if (is_array($name))
 		{
@@ -296,7 +296,7 @@
 	* @param	bool
 	* @return	string
 	*/
-	function server($index = '', $xss_clean = FALSE)
+	public function server($index = '', $xss_clean = FALSE)
 	{
 		return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
 	}
@@ -309,7 +309,7 @@
 	* @access	public
 	* @return	string
 	*/
-	function ip_address()
+	public function ip_address()
 	{
 		if ($this->ip_address !== FALSE)
 		{
@@ -369,10 +369,16 @@
 	*
 	* @access	public
 	* @param	string
-	* @return	string
+	* @return	bool
 	*/
-	function valid_ip($ip)
+	public function valid_ip($ip)
 	{
+		// if php version >= 5.2, use filter_var to check validate ip.
+		if (function_exists('filter_var'))
+		{
+			return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
+		}
+
 		$ip_segments = explode('.', $ip);
 
 		// Always 4 segments needed
@@ -407,7 +413,7 @@
 	* @access	public
 	* @return	string
 	*/
-	function user_agent()
+	public function user_agent()
 	{
 		if ($this->user_agent !== FALSE)
 		{
@@ -435,7 +441,7 @@
 	* @access	private
 	* @return	void
 	*/
-	function _sanitize_globals()
+	private function _sanitize_globals()
 	{
 		// It would be "wrong" to unset any of these GLOBALS.
 		$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
@@ -536,7 +542,7 @@
 	* @param	string
 	* @return	string
 	*/
-	function _clean_input_data($str)
+	private function _clean_input_data($str)
 	{
 		if (is_array($str))
 		{
@@ -594,7 +600,7 @@
 	* @param	string
 	* @return	string
 	*/
-	function _clean_input_keys($str)
+	private function _clean_input_keys($str)
 	{
 		if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
 		{
@@ -618,6 +624,7 @@
 	 * In Apache, you can simply call apache_request_headers(), however for
 	 * people running other webservers the function is undefined.
 	 *
+	 * @access	public
 	 * @param	bool XSS cleaning
 	 *
 	 * @return array
@@ -661,6 +668,7 @@
 	 *
 	 * Returns the value of a single member of the headers class member
 	 *
+	 * @access	public
 	 * @param 	string		array key for $this->headers
 	 * @param	boolean		XSS Clean or not
 	 * @return 	mixed		FALSE on failure, string on success
@@ -692,6 +700,7 @@
 	 *
 	 * Test to see if a request contains the HTTP_X_REQUESTED_WITH header
 	 *
+	 * @access	public
 	 * @return 	boolean
 	 */
 	public function is_ajax_request()
@@ -706,6 +715,7 @@
 	 *
 	 * Test to see if a request was made from the command line
 	 *
+	 * @access	public
 	 * @return 	boolean
 	 */
 	public function is_cli_request()
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index a34809e..c78583f 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -1079,7 +1079,7 @@
 	 *
 	 * @access	public
 	 * @param	string
-	 * @return	string
+	 * @return	bool
 	 */
 	public function valid_ip($ip)
 	{
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 3b4c72b..ba13808 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -79,7 +79,7 @@
 	<li>Helpers
 		<ul>
 			<li>Added <samp>increment_string()</samp> to <a href="helpers/string_helper.html">String Helper</a> to turn "foo" into "foo-1" or "foo-1" into "foo-2".</li>
-        		<li>Altered form helper - made action on form_open_multipart helper function call optional.  Fixes (#65)</li>
+			<li>Altered form helper - made action on form_open_multipart helper function call optional.  Fixes (#65)</li>
 			<li><samp>url_title()</samp> will now trim extra dashes from beginning and end.</li>
 			<li>Improved speed of <a href="helpers/string_helper.html">String Helper</a>'s <b>random_string()</b> method</li>
 		</ul>
@@ -102,6 +102,7 @@
 			<li>Added max_filename_increment config setting for Upload library.</li>
 			<li><samp>CI_Loader::_ci_autoloader()</samp> is now a protected method.</li>
 			<li>Added <kbd>is_unique</kbd> to the <a href="libraries/form_validation.html">Form Validation library</a>.</li>
+			<li>Modified valid_ip() to use PHP's filter_var() when possible (>= PHP 5.2) in the <a href="libraries/form_validation.html">Form Validation</a> library.</li>
 		</ul>
 	</li>
 	<li>Core
@@ -117,9 +118,9 @@
 	<li class="reactor">If a config class was loaded first then a library with the same name is loaded, the config would be ignored.</li>
 	<li class="reactor">Fixed a bug (Reactor #19) where 1) the 404_override route was being ignored in some cases, and 2) auto-loaded libraries were not available to the 404_override controller when a controller existed but the requested method did not.</li>
 	<li class="rector">Fixed a bug (Reactor #89) where MySQL export would fail if the table had hyphens or other non alphanumeric/underscore characters.</li>
-    <li class="reactor">Fixed a bug (#200) where MySQL queries would be malformed after calling <samp>count_all()</samp> then <samp>db->get()</samp></li>
-    <li class="reactor">Fixed bug #105 that stopped query errors from being logged unless database debugging was enabled</li>
-    <li>Fixed a bug (#181) where a mis-spelling was in the form validation language file.</li>
+	<li class="reactor">Fixed a bug (#200) where MySQL queries would be malformed after calling <samp>count_all()</samp> then <samp>db->get()</samp></li>
+	<li class="reactor">Fixed bug #105 that stopped query errors from being logged unless database debugging was enabled</li>
+	<li>Fixed a bug (#181) where a mis-spelling was in the form validation language file.</li>
 	<li>Fixed a bug (#160) - Removed unneeded array copy in the file cache driver.</li>
 	<li>Fixed a bug (#150) - <samp>field_data()</samp> now correctly returns column length.</li>
 	<li>Fixed a bug (#8) - <samp>load_class()</samp> now looks for core classes in <samp>APPPATH</samp> first, allowing them to be replaced.</li>