Created
December 4, 2013 18:43
-
-
Save georgestephanis/7793119 to your computer and use it in GitHub Desktop.
Returns true if the IP Address passed in could have been mistakenly flagged as in the reserved range by FILTER_FLAG_NO_RES_RANGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns true if the IP Address passed in could have been mistakenly | |
* flagged as in the reserved range by FILTER_FLAG_NO_RES_RANGE | |
* | |
* @see https://bugs.php.net/bug.php?id=66229 | |
* @see https://github.com/php/php-src/commit/d1314893fd1325ca6aa0831101896e31135a2658 | |
* @param $ip string An IP Address | |
* @return bool | |
*/ | |
function php_bug_66229_check( $ip ) { | |
if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) { | |
return false; | |
} | |
$ip_arr = array_map( 'intval', explode( '.', $ip ) ); | |
if ( 128 == $ip_arr[0] && 0 == $ip_arr[1] ) { | |
return true; | |
} | |
if ( 191 == $ip_arr[0] && 255 == $ip_arr[1] ) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment