summaryrefslogtreecommitdiffstats
path: root/system/core
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-07 23:01:10 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-07 23:01:10 +0200
commit728115901ff93183f8f2f695417621cfc799a865 (patch)
treed96ef42b673f924f0544a201c4037b86207f271f /system/core
parent45927d86ee8faafbbc68a4bea544b3f50494d7e5 (diff)
Fixed valid_ip() for PHP < 5.2
Diffstat (limited to 'system/core')
-rwxr-xr-xsystem/core/Input.php43
1 files changed, 21 insertions, 22 deletions
diff --git a/system/core/Input.php b/system/core/Input.php
index 4b7622cbe..47fc0f887 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -389,11 +389,10 @@ class CI_Input {
break;
}
- return filter_var($ip, FILTER_VALIDATE_IP, $flag) !== FALSE;
+ return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
}
-
- // If it's not we'll do it manually
- if ($which != 'ipv6' OR $which != 'ipv4')
+
+ if ($which !== 'ipv6' && $which !== 'ipv4')
{
if (strpos($ip, ':') !== FALSE)
{
@@ -405,16 +404,16 @@ class CI_Input {
}
else
{
- return FALSE;
+ return $this->_valid_ipv4($ip) OR $this->_valid_ipv6($ip);
}
}
-
+
$func = '_valid_'.$which;
return $this->$func($ip);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Validate IPv4 Address
*
@@ -429,7 +428,7 @@ class CI_Input {
$ip_segments = explode('.', $ip);
// Always 4 segments needed
- if (count($ip_segments) != 4)
+ if (count($ip_segments) !== 4)
{
return FALSE;
}
@@ -438,7 +437,7 @@ class CI_Input {
{
return FALSE;
}
-
+
// Check each segment
foreach ($ip_segments as $segment)
{
@@ -452,9 +451,9 @@ class CI_Input {
return TRUE;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Validate IPv6 Address
*
@@ -467,33 +466,33 @@ class CI_Input {
// 8 groups, separated by :
// 0-ffff per group
// one set of consecutive 0 groups can be collapsed to ::
-
+
$groups = 8;
$collapsed = FALSE;
-
+
$chunks = array_filter(
preg_split('/(:{1,2})/', $str, NULL, PREG_SPLIT_DELIM_CAPTURE)
);
-
+
// Rule out easy nonsense
if (current($chunks) == ':' OR end($chunks) == ':')
{
return FALSE;
}
-
+
// PHP supports IPv4-mapped IPv6 addresses, so we'll expect those as well
if (strpos(end($chunks), '.') !== FALSE)
{
$ipv4 = array_pop($chunks);
-
+
if ( ! $this->_valid_ipv4($ipv4))
{
return FALSE;
}
-
+
$groups--;
}
-
+
while ($seg = array_pop($chunks))
{
if ($seg[0] == ':')
@@ -502,19 +501,19 @@ class CI_Input {
{
return FALSE; // too many groups
}
-
+
if (strlen($seg) > 2)
{
return FALSE; // long separator
}
-
+
if ($seg == '::')
{
if ($collapsed)
{
return FALSE; // multiple collapsed
}
-
+
$collapsed = TRUE;
}
}