6

使用 PHP 禁止国内 ip 访问网站

 3 years ago
source link: https://yjyj.net/learn/6282.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用 PHP 禁止国内 ip 访问网站

php怎么禁止国内ip访问网站?

用php代码限制国内IP访问我们网站

利用淘宝的IP接口来判断IP,是否是国内的ip,是国内(CN)的就不允许访问。

$ip = $_SERVER['REMOTE_ADDR'];
$content = file_get_contents(‘http://ip.taobao.com/service/getIpInfo.php?ip=’.$ip);
$banned = json_decode(trim($content), true);
$lan = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if((!empty($banned['data']['country_id']) && $banned['data']['country_id'] == ‘CN’) || strstr($lan, ‘zh’))
{
header(“HTTP/1.0 404 Not Found”);
echo ‘HTTP/1.0 404 Not Found’;
exit;
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK