PHP获取用户真实,PHP禁止个别IP访问网站_php实例_脚本之家

PHP获取用户真实,PHP禁止个别IP访问网站_php实例_脚本之家

想不让有些IP访谈网址,能够封他的IP,上边就提供这一个方法。看下边包车型大巴代码。复制代码 代码如下:function get_ip_data(){
$ip=file_get_contents(“;
$ip = json_decode{ return false; } $data = $ip->data;
if($data[‘region’]==’湖北省’ && !isCrawler{ exit; }}

协调不需ip库,免更新。
淘宝IP库:

function isCrawler() { $spiderSite= array( “TencentTraveler”,
“Baiduspider+”, “BaiduGame”, “Googlebot”, “msnbot”, “Sosospider+”,
“Sogou web spider”, “ia_archiver”, “Yahoo! Slurp”, “YoudaoBot”, “Yahoo
Slurp”, “MSNBot”, “Java “, “BaiDuSpider”, “Voila”, “Yandex bot”,
“BSpider”, “twiceler”, “Sogou Spider”, “Speedy Spider”, “Google
AdSense”, “Heritrix”, “Python-urllib”, “Alexa “, “Ask”, “Exabot”,
“Custo”, “OutfoxBot/YodaoBot”, “yacy”, “SurveyBot”, “legs”,
“lwp-trivial”, “Nutch”, “StackRambler”, “The web archive “, “Perl tool”,
“MJ12bot”, “Netcraft”, “MSIECrawler”, “WGet tools”, “larbin”, “Fish
search”, );
if(in_array(strtolower($_SERVER[‘HTTP_USER_AGENT’]),$spiderSite)){
return true; }else{ return false; }}

 

//取顾客端 ipfunction get_client_ip(){ if { 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 { $realip = getenv;
} else { $realip = getenv; } } return $realip;}

/**

* 获取顾客真正 IP

*/

function getIP()

{

static $realip;

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;

}

/**

* 获取 IP 地理位置

* 淘宝IP接口

* @Return: array

*/

function getCity($ip)

{

$url=”;

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

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

return false;

}

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

return $data;

}

admin

网站地图xml地图