WordPress屏蔽垃圾IP访问网站避免垃圾评论
随风飘扬 闲聊 2016年03月03日10:38 3425
一直以来本站一直遭受angelina这个名称和180.97.106.41IP的垃圾评论,今天终于想起
一直以来本站一直遭受angelina这个名称和180.97.106.41IP的垃圾评论,今天终于想起来这个事情还没有完成,于是着手屏蔽其,屏蔽方法有两种,一种是在wordpress加载前判断IP,若为黑名单内,则停止加载WP,代码放在wordpress的index.php内require( dirname( __FILE__ ) . '/wp-blog-header.php' );
前面即可
代码如下:$blocked_ip=array("180.97.106","",);
$ip = $_SERVER["REMOTE_ADDR"];
$arr = explode('.',$ip);
$blocked = $arr[0].'.'.$arr[1].'.'.$arr[2];
if(in_array($blocked,$blocked_ip))exit("禁止访问!Your IP was Blocked");
这样IP段为180.97.106.0~255的IP就不能访问本站了;
还有一种方法是在空间的根目录的.htaccess加入以下代码,不过有些虚拟空间服务商不支持.htaccess:
1、如果要屏蔽某一特定IP可以使用:order allow,deny
deny from 142.4.108.109
allow from all
2、如果想要屏蔽多个IP地址,只需多加几个deny from 即可order allow,deny
deny from 192.168.0.2
deny from 192.168.0.3
deny from 192.168.0.4
allow from all
3、如果需要屏蔽整个IP段,可以使用order allow,deny
deny from 192.168.0
allow from all
4、如果只想屏蔽IP段中的一小部分IP,则可使用order allow,deny
deny from 192.168.0.100/200
allow from all
完工,以后来自被屏蔽ip的访问只会显示403页面
Statement: all articles / drawings reproduced on this website are for the purpose of transmitting more information and facilitating discussion, which does not mean that the website, the host and the organizer agree with their opinions or confirm the authenticity of their contents. The contents of the articles are for reference only. If the rights of the original author are violated, please contact the website administrator.
Comment list
-
No data