您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP禁止个别IP访问网站_PHP教程

2025/12/26 7:41:57发布23次查看
想不让某个ip访问网站,可以封他的ip,下面就提供这个方法。看下面的代码。
复制代码 代码如下:
function get_ip_data(){  
    $ip=file_get_contents(http://ip.taobao.com/service/getipinfo.php?ip=.get_client_ip());
    $ip = json_decode($ip);
    if($ip->code){
        return false;
    }
    $data = (array) $ip->data;
    if($data['region']=='湖北省' && !iscrawler()){
        exit('http://www.a.net');
    }
}function iscrawler() {
        $spidersite= array(
                        tencenttraveler,
                        baiduspider+,
                        baidugame,
                        googlebot,
                        msnbot,
                        sosospider+,
                        sogou web spider,
                        ia_archiver,
                        yahoo! slurp,
                        youdaobot,
                        yahoo slurp,
                        msnbot,
                        java (often spam bot),
                        baiduspider,
                        voila,
                        yandex bot,
                        bspider,
                        twiceler,
                        sogou spider,
                        speedy spider,
                        google adsense,
                        heritrix,
                        python-urllib,
                        alexa (ia archiver),
                        ask,
                        exabot,
                        custo,
                        outfoxbot/yodaobot,
                        yacy,
                        surveybot,
                        legs,
                        lwp-trivial,
                        nutch,
                        stackrambler,
                        the web archive (ia archiver),
                        perl tool,
                        mj12bot,
                        netcraft,
                        msiecrawler,
                        wget tools,
                        larbin,
                        fish search,
                );
        if(in_array(strtolower($_server['http_user_agent']),$spidersite)){
            return true;
        }else{
            return false;
        }
}
//取客户端 ip
function get_client_ip()
{
    if (isset($_server)){
            if (isset($_server[http_x_forwarded_for])){
                $realip = $_server[http_x_forwarded_for];
            } else if (isset($_server[http_client_ip])) {
                $realip = $_server[http_client_ip];
            } else {
                $realip = $_server[remote_addr];
            }
    } else {
            if (getenv(http_x_forwarded_for)){
                $realip = getenv(http_x_forwarded_for);
            } else if (getenv(http_client_ip)) {
                $realip = getenv(http_client_ip);
            } else {
                $realip = getenv(remote_addr);
            }
        }
    return $realip;
}
http://www.bkjia.com/phpjc/825056.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/825056.htmltecharticle想不让某个ip访问网站,可以封他的ip,下面就提供这个方法。看下面的代码。 复制代码 代码如下: function get_ip_data(){ $ip=file_get_contents(ht...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product