Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Created December 4, 2013 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgestephanis/7793119 to your computer and use it in GitHub Desktop.
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
<?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