本子

屏蔽某个省份访问网站
将下面代码加入网站首页,适合php环境 <?php /** * * ban_ip.php(屏蔽地方IP) *...
扫描右侧二维码阅读全文
03
2019/05

屏蔽某个省份访问网站

将下面代码加入网站首页,适合php环境

<?php
/**
*
* ban_ip.php(屏蔽地方IP)
*/
header("Content-type: text/html; charset=utf-8");
$verification = 'SX';//需要屏蔽的省份,拼音首字母大写
$ip = $_SERVER['REMOTE_ADDR'];//获取访客IP
$antecedents = $_SERVER['HTTP_REFERER'];//访客来路地址
$result = file_get_contents("http://ip-api.com/json/".$ip);//IP数据库。
$address = json_decode($result,true);
//判断访客是否属于山西省,是否来自百度,是否来自谷歌
if($address['region'] == $verification && strpos($antecedents, 'baidu') === false && strpos($antecedents, 'google') === false){
    sleep(9999999999999999);                
    echo '<div style="margin-top:20%;"><center><h1> 暂时无法访问。</h1></div></center></html>';
    exit;
}
?>
Last modification:May 3rd, 2019 at 01:07 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment