防洪:会话或数​​据库存储ips

发布于 2024-09-09 05:14:58 字数 495 浏览 0 评论 0原文

现在我在所有网站中使用防洪功能:

function flood($name,$time)
{
 $name = 'tmptmptmp'.$name;
 if(!isset($_SESSION[$name]))
 {
  $_SESSION[$name] = time();
  return true;
 }
 else
 {
  if(time()-$time > $_SESSION[$name])
  {
   $_SESSION[$name] = time();
   return true;
  }
  else
  {
   return false;
  }
 }
}

我这样使用它:

if(flood('post',60)) do something;
else 'you're posting too fast';

这种方式安全吗?或者我是否需要用存储 ips 的数据库表替换/完成它并检查他们是否之前发出了请求?

right now I'm using an antiflood function in all my websites :

function flood($name,$time)
{
 $name = 'tmptmptmp'.$name;
 if(!isset($_SESSION[$name]))
 {
  $_SESSION[$name] = time();
  return true;
 }
 else
 {
  if(time()-$time > $_SESSION[$name])
  {
   $_SESSION[$name] = time();
   return true;
  }
  else
  {
   return false;
  }
 }
}

I use it this way :

if(flood('post',60)) do something;
else 'you're posting too fast';

Is this way safe ? Or do I need to replace it/complete it with a db table stocking ips and checking if they did a request earlier ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枉心 2024-09-16 05:14:58

这取决于。您的用户清除 cookie 以绕过您的防洪保护的可能性有多大?我想说,如果他们必须再次登录,99% 的用户甚至不会打扰。

但是当然,如​​果您确实想要更好的方法,请将 ip 存储在数据库中。但即便如此,也可以通过获得新的 IP 来克服这一点。

It depends. How likely are your users going to clear their cookies to get past your anti-flood protection? I'll say that if they have to login again, 99% of the users won't even bother.

But sure, if you really want better method, store the ips in the DB. But even that can be defeated by getting a new IP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文