PHP - 24 小时阻止 IP
我有一个 PHP 文件,我想收集人们的 IP,然后如果他们的 IP 在过去 24 小时内运行过该文件,则阻止 PHP 文件继续运行。我尝试过使用 cookie,但它一直给我“无法更改标头”错误。另外,人们可以清除他们的cookie。基本上,它会保留运行 php 文件的每个人的 IP,然后如果他们尝试在 24 小时内访问它,它会“回显“您可以在 24 小时内再次访问此文件”并且不会运行整个文件。然后他们可以24小时后再做一次。
I have a PHP file that I want to collect people's IP's then prevent the PHP file from continuing if their IP has run the file within the last 24 hours. I've tried with cookies, but it kept giving me "can't change header" errors. Plus, people could just clear their cookies. Basically, it keeps the IP's of everyone who runs the php file, then if they try to access it within 24 hours it does "echo "You can access this again in 24 hours" and doesn't run the whole file. Then they can do it again after 24 hours.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
每次查看页面时,都会在删除超过 24 小时的条目后检查 IP 地址是否在数据库表中。
但是,这将阻止所有使用共享连接的用户。最好要求登录,然后阻止每个用户的访问。
Every time the page is viewed check if the ip address is in a database table after removing entries that are over 24 hours old
However, this will block all users using a shared connection. It is better to require a login, then block access per user.
我认为对你来说,拥有一个存储每个 ip 的最后访问时间的表会更容易,其结构如下:
将
$_SERVER['SERVER_ADDR']
中的 IP 地址转换为带有inet_pton()
的整数值,并进行简单的选择该数据库表I think it would be much easier for you to have a table that stores the last access time for each ip, with a structure like:
you transform from IP address in
$_SERVER['SERVER_ADDR']
to an integer value withinet_pton()
, and do a simple select in that DB table我可能经常看到的方法:
IP 禁止
优点:
缺点:
Cookie
优点:
缺点:< /strong>
用户登录
优点:
缺点:
注意,
$_SERVER
是持有IP 地址和有关请求标头的其他信息。Approaches I can possibly see working more often than not:
IP Banning
Pros:
Cons:
Cookies
Pros:
Cons:
User login
Pros:
Cons:
Note,
$_SERVER
is what holds the IP address and other information about the request headers.您可以简单地跟踪 IP 及其访问 php 文件的日期,并在 24 小时过去后(如果他们尝试重新访问)更新此日期。
我希望这有帮助。
You can simply track ip's with a date they accessed the php file, and update this date after 24 hours has passed if they try to re-access.
I hope this helps.
像这样的东西:
更新:-
有用的链接
http://perishablepress.com/press/2007/07/03/how-to-block-ip-addresses-with-php/
http://forums.digitalpoint.com/showthread.php?t=67344
Something like this:
Update :-
Useful links
http://perishablepress.com/press/2007/07/03/how-to-block-ip-addresses-with-php/
http://forums.digitalpoint.com/showthread.php?t=67344