Created
April 26, 2012 20:02
-
-
Save geeksunny/2502609 to your computer and use it in GitHub Desktop.
A PHP function to determine if a given IP address lies within a given 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 | |
function check_ip_range($target, $range_start, $range_end) | |
{ | |
if (ip2long($target) >= ip2long($range_start) && ip2long($target) <= ip2long($range_end)) | |
return true; | |
else | |
return false; | |
} | |
// Should return false | |
var_dump(check_ip_range("127.0.0.1","10.0.0.0","10.255.255.255")); | |
// Should return true | |
var_dump(check_ip_range("10.6.0.134","10.0.0.0","10.255.255.255")); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment