淘宝接口获取当前地址,PHP禁止个别IP访问网站

2019-07-22 作者:yzc216.com官网   |   浏览(78)

想不让某个IP访问网站,可以封他的IP,下面就提供这个方法。看下面的代码。

1,首先获取IP地址

复制代码 代码如下:

2,通过淘宝接口获取当前为止

function get_ip_data(){  
    $ip=file_get_contents("));
    $ip = json_decode($ip);
    if($ip->code){
        return false;
    }
    $data = (array) $ip->data;
    if($data['region']=='湖北省' && !isCrawler()){
        exit('');
    }
}

============第一部分===========

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;
        }
}

function getIP()

//取客户端 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;
}

{

您可能感兴趣的文章:

  • 用php代码限制国内IP访问我们网站
  • PHP实现的限制IP投票程序IP来源分析
  • php限制ip地址范围的方法
  • 用php来限制每个ip每天浏览页面数量的实现思路
  • php中限制ip段访问、禁止ip提交表单的代码分享
  • PHP中限制IP段访问、禁止IP提交表单的代码
  • php IP及IP段进行访问限制的代码
  • 如何限制访问者的ip(PHPBB的代码)
  • 简单实现限定phpmyadmin访问ip的方法
  • 禁止IP访问网站的多种方法分享(linux,php,nginx,apache)
  • PHP 只允许指定IP访问(允许*号通配符过滤IP)
  • PHP实现限制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;

}

=============第二部分============

function getAddr($ip = '')

{

// 获取得到一个数组country(国家),area(地区),region(省),city(城市),isp(网络运营商),ip(ip地址)

if($ip == ''){

$url = "";

$ip=json_decode(file_get_contents($url),true);

$data = $ip;

}else{

$url=";

$ip=json_decode(file_get_contents($url));

if((string)$ip->code=='1'){

return false;

}

$data = (array)$ip->data;

}

return $data;

}

本文由yzc216亚洲城发布于yzc216.com官网,转载请注明出处:淘宝接口获取当前地址,PHP禁止个别IP访问网站

关键词: yzc216亚洲城 yzc216.com官网