Last active
August 29, 2015 14:09
-
-
Save sandacn/ad6686249d7bc0ee0014 to your computer and use it in GitHub Desktop.
判断ip是否为内网ip
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 is_intranet_ip($ip = null) { | |
if (!$ip) { | |
$ip = $_SERVER['REMOTE_ADDR']; | |
} | |
$long_ip = ip2long($ip); | |
$ret = false; | |
// 分别判断10. 192.168. 172.16-31. 127.0.0.1 | |
if ($long_ip >> 24 == 0xa || $long_ip >> 20 == 0xac1 || $long_ip >> 16 == 0xc0a8 || $long_ip == 0x7f000001) { | |
$ret = true; | |
} | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment