阻止IP地址自动使用PHP和htaccess的 [英] Block ip addresses automatically using PHP and htaccess

查看:253
本文介绍了阻止IP地址自动使用PHP和htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图让尽可能安全的登录系统。经过十不良企图我想有就有的IP地址被阻止。我怎样才能打开PHP文件,并添加一行到我的块IP地址code?这是我的htaccess文件:

I have a login system that I am trying to make as secure as possible. After ten bad attempts I want to have there ip address blocked. How can I open a file in PHP and add a line to my block ip addresses code? Here is my htaccess file:

#Turn on RewriteEngine
RewriteEngine on
#Don't allow file indexing pages
Options -Indexes
#Follow Symbolic Links
Options +FollowSymLinks
#Set default language and charset
DefaultLanguage en-US
AddDefaultCharset UTF-8
#Set the server timezone
SetEnv TZ America/Vancouver

#Don't need extention for PHP files
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#Block bad IP Addresses
RewriteCond %{REMOTE_ADDR} ^217.172.179.*$ [OR]
RewriteCond %{REMOTE_ADDR} ^217.172.180.*$
RewriteCond %{REQUEST_URI} !/error/blocked.php$ [NC]
RewriteRule ^(.*)$ /error/blocked.php [R,NC,L]

我想的PHP文件中加入一行:

I would like the PHP file to add the line:

RewriteCond %{REMOTE_ADDR} ^IPHERE$ [OR]

在注释块错误的IP地址对的。

right under the comment Block bad IP Addresses.

推荐答案

我不建议直接编辑.htaccess文件。

I wouldn't recommend editing the .htaccess file directly.

相反,在PHP中的文件或数据库表来保存所有被列入黑名单的IP地址,并将其与测试,而不是Apache的身边。

Instead, have a file or a database table to save all of the blacklisted IP addresses, and test against that in PHP, rather than on Apache's side.

这篇关于阻止IP地址自动使用PHP和htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆