限制IP访问,授权IP,授权域名,支持单个,多个,通配符,IP段,支持黑白名单<?php <br />
// 限制域名测试<br>
$domain = '2.baidu.com';<br>
$domain_list = '*.baidu.com,qq.com';<br>
if (in_host ( $domain, $domain_list )) {<br>
echo ('domain in');<br>
} else {<br>
echo ('domain is not in');<br>
}<br>
<br>
// 限制IP测试<br>
$host = '127.1.1.88';<br>
$list = '127.0.0.*,192.168.1.1,192.168.1.70,127.1.1.33-127.1.1.100';<br>
if (in_host ( $host, $list )) {<br>
echo ('ip in');<br>
} else {<br>
echo ('ip is not in');<br>
}<br>
/**<br>
* HOST访问限制 支持 IP(单IP,多IP,*通配符,IP段) 域名(单域名,多域名,*通配符)<br>
* 根据判断实现IP地址 白名单黑名单<br>
* Author:70(qq781787584)<br>
* @param unknown $host 当前host 127.0.0.2<br>
* @param unknown $list 允许的host列表 127.0.0.*,192.168.1.1,192.168.1.70,127.1.1.33-127.1.1.100<br>
* @return boolean<br>
*/<br>
function in_host($host, $list) {<br>
$list = ',' . $list . ',';<br>
$is_in = false;<br>
// 1.判断最简单的情况<br>
$is_in = strpos ( $list, ',' . $host . ',' ) === false ? false : true;<br>
// 2.判断通配符情况<br>
if (! $is_in && strpos ( $list, '*' ) !== false) {<br>
$hosts = array ();<br>
$hosts = explode ( '.', $host );<br>
// 组装每个 * 通配符的情况<br>
foreach ( $hosts as $k1 => $v1 ) {<br>
$host_now = '';<br>
foreach ( $hosts as $k2 => $v2 ) {<br>
$host_now .= ($k2 == $k1 ? '*' : $v2) . '.';<br>
}<br>
// 组装好后进行判断<br>
if (strpos ( $list, ',' . substr ( $host_now, 0, - 1 ) . ',' ) !== false) {<br>
$is_in = true;<br>
break;<br>
}<br>
}<br>
}<br>
// 3.判断IP段限制<br>
if (! $is_in && strpos ( $list, '-' ) !== false) {<br>
$lists = explode ( ',', trim ( $list, ',' ) );<br>
$host_long = ip2long ( $host );<br>
foreach ( $lists as $k => $v ) {<br>
if (strpos ( $v, '-' ) !== false) {<br>
list ( $host1, $host2 ) = explode ( '-', $v );<br>
if ($host_long >= ip2long ( $host1 ) && $host_long
$is_in = true;<br>
break;<br>
}<br>
}<br>
}<br>
}<br>
return $is_in;<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元