Created
April 27, 2010 06:27
-
-
Save slywalker/380409 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function checkIPMask($ip, $mask) { | |
list($maskIp, $maskBit) = explode('/', $mask); | |
$maskIpLong = ip2long($maskIp) >> (32 - $maskBit); | |
$ipLong = ip2long($ip) >> (32 - $maskBit); | |
if ($maskIpLong !== $ipLong) { | |
return false; | |
} | |
return true; | |
} | |
$mask = '210.161.126.144/28'; | |
$ip = '210.161.126.144'; | |
var_dump(checkIPMask($ip, $mask)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment