Skip to content

Instantly share code, notes, and snippets.

@sandacn
Last active August 29, 2015 14:09
Show Gist options
  • Save sandacn/ad6686249d7bc0ee0014 to your computer and use it in GitHub Desktop.
Save sandacn/ad6686249d7bc0ee0014 to your computer and use it in GitHub Desktop.
判断ip是否为内网ip
<?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