问题
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?
I'd prefer not to log every visitor's ip address, etc... something simple - in C# asp.net mvc.
回答1:
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.
Pseudocode to implement:
if (Session["HasCountedThisVisitor"] == null)
{
counter++;
Session["HasCountedThisVisitor"] = true;
}
回答2:
Cookie or a session variable that you check if it has been set, before increasing the counter..
回答3:
Why?
There are tons of free logging tools, some analyze your IIS logs, some give you some javascript to place on your pages. Google Analytics is pretty awesome and free.
You're reinventing the wheel here.
来源:https://stackoverflow.com/questions/3954275/how-best-to-block-multiple-counts-on-a-counter