如何最有效地阻止多个"计数"在柜台? [英] How best to block multiple "counts" on a counter?

查看:123
本文介绍了如何最有效地阻止多个"计数"在柜台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了一个真正潇洒的计数器,只是增加了一个计数器字段时,访问撞击它。这还不包括页面命中,但它仍然是俗气。

I've got a real cheesy counter, just adds one to the counter field when a visit hits it. It's not counting page hits, but it's still cheesy.

我需要做的是停止只是击中刷新一遍又一遍的人。什么是最简单的是要完成这件事?饼干?

What I need to do is stop someone from just hitting refresh over and over. What's the simplest was to get this done? Cookies?

我倒是preFER不记录每个访问者的IP地址,等等。简单的东西 - 在C#中asp.net mvc的

I'd prefer not to log every visitor's ip address, etc... something simple - in C# asp.net mvc.

推荐答案

是的,饼干是一个简单的方法来实现这一目标。更简单是简单地设置会话值 - 如果被设置,这次访问​​已被注册,所以我们不应该再增加计数器

Yes, cookies would be a simple way to achieve that. Even simpler would be to simply set a value in Session - if that is set, this visit has been registered, so we should not increment the counter again.

这种方式,您也将算访问每个会话,其中大部分往往是独特的访问是最好的措施。

This way you will also count a "visit" per session, which most often is the best measure for unique visits.

伪code来实现:

if (Session["HasCountedThisVisitor"] == null) 
{
    counter++; 
    Session["HasCountedThisVisitor"] = true;
}

这篇关于如何最有效地阻止多个"计数"在柜台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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