Django中的垃圾邮件计数器 [英] Spam proof hit counter in Django

查看:211
本文介绍了Django中的垃圾邮件计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过最流行的Django命中计数器解决方案,并没有一个似乎解决了垃圾邮件刷新按钮的问题。



我真的要登录每个访问者的IP ,以防止他们通过垃圾邮件刷新按钮(或编写一个快速而肮脏的脚本来为他们​​进行人为的提升页面浏览量)?



更多信息



所以现在你可以用以下几行Python代码来夸大你的观点数量。哪一个很少,你真的不需要写一个脚本,你可以将它输入一个交互式会话:

 从urllib import urlopen 

num_of_times_to_hit_page = 100
url_of_the_page =http://example.com

for x in range(num_of_times_to_hit_page):
urlopen(url_of_the_page)



解决方案我可能会使用


$ b $对我来说,当您需要在每个页面视图中对数据库进行一系列写入时,这是一个非常糟糕的情况,但是我猜这是无法帮助的。我要实施IP日志记录,因为几个用户人为地夸大了他们的观点数量。这不是他们是坏人,甚至是坏的用户。



看到解决缓存问题的答案...我是先去追求这条路线。将更新结果。



对于什么是值得的,似乎Stack Overflow正在使用Cookie(我不能增加我自己的视图数量,但它增加了当我在另一个浏览器中访问该网站时。)



我认为这个好处太多了,这种欺骗现在太容易了。 / p>

感谢大家的帮助。

解决方案

记录IP可能最安全这不是完美的,但它比Cookie更好,比用户要求注册更麻烦。也就是说,我建议不要在DB中保存这些。相反,使用Django的低级缓存框架。关键是ip和值一个简单的布尔值。即使是基于文件的缓存也应该是相当快的,但是如果你真的希望有大量流量,那么尽管使用memchached作为缓存后端。



这样的东西应该可以工作:

  ip = request.META ['REMOTE_ADDR'] 
has_voted = cache.get(ip)
如果没有has_voted:
cache.set(ip,True)
#code保存投票在这里


I already looked at the most popular Django hit counter solutions and none of them seem to solve the issue of spamming the refresh button.

Do I really have to log the IP of every visitor to keep them from artificially boosting page view counts by spamming the refresh button (or writing a quick and dirty script to do it for them)?

More information

So right now you can inflate your view count with the following few lines of Python code. Which is so little that you don't really need to write a script, you could just type it into an interactive session:

from urllib import urlopen

num_of_times_to_hit_page = 100
url_of_the_page = "http://example.com"

for x in range(num_of_times_to_hit_page):
    urlopen(url_of_the_page)

Solution I'll probably use

To me, it's a pretty rough situation when you need to do a bunch of writes to the database on EVERY page view, but I guess it can't be helped. I'm going to implement IP logging due to several users artificially inflating their view count. It's not that they're bad people or even bad users.

See the answer about solving the problem with caching... I'm going to pursue that route first. Will update with results.

For what it's worth, it seems Stack Overflow is using cookies (I can't increment my own view count, but it increased when I visited the site in another browser.)

I think that the benefit is just too much, and this sort of 'cheating' is just too easy right now.

Thanks for the help everyone!

解决方案

Logging an IP is probably the safest. It's not perfect, but it's better than cookies and less annoying to users than requiring a signup. That said, I'd recommend not bothering with saving these in a DB. Instead, use Django's low-level caching framework. The key would be the ip and the value a simple boolean. Even a file-based cache should be pretty fast, though go with memchached as the cache backend if you really expect heavy traffic.

Something like this should work:

ip = request.META['REMOTE_ADDR']
has_voted = cache.get(ip)
if not has_voted:
    cache.set(ip, True)
    #code to save vote goes here

这篇关于Django中的垃圾邮件计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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