- A+
所属分类:域名相关
有些网站不适合国内访客访问,需要屏蔽国内IP,比如一些外贸站,禁止中国国内IP访问网站的方法有很多,这里分享几个常用且有效的方法:
1. 利用.htaccess文件屏蔽中国IP
禁止一个ip段
deny from 218.2.135.0/255
同时设置一下允许自己的IP可访问
中国IP段地址大全
2. 利用JS判断语句代码加载到网站footer或者header
3. 利用被屏蔽的DNS来解析域名
4. 当然也可通过屏蔽中文操作系统来禁止国内IP访问,代码如下:(这个比较狠,慎用)
<?php
$client_sys_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; // system language
if (preg_match ("/^zh-cn/i",$client_sys_language)) {
echo "
Forbidden
You don’t have permission to access /on this server.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
";
exit;
}
?>
$client_sys_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; // system language
if (preg_match ("/^zh-cn/i",$client_sys_language)) {
echo "
Forbidden
You don’t have permission to access /on this server.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
";
exit;
}
?>
5,屏蔽中文浏览器
<script type="text/javascript">
if (navigator.language)
var language = navigator.language;
else
var language = navigator.browserLanguage;
if(language.indexOf('zh') > -1)document.location.href = 'http://www.google.com';
</script>
if (navigator.language)
var language = navigator.language;
else
var language = navigator.browserLanguage;
if(language.indexOf('zh') > -1)document.location.href = 'http://www.google.com';
</script>
您可以选择一种方式赞助本站
赏