Answer the question
In order to leave comments, you need to log in
How to count site visitors?
The task is to count the number of visitors for pages.
If you simply count the opening of pages, as, for example, on the Toaster, then when the page is updated, the counter will be updated.
Options for which you can catch on:
1. IP - but you can’t just cling to IP, in the case of, for example, mobile Internet, one address can be for several thousand devices.
2. Information about the client - about the browser, OS, etc. In general, all the information that can be obtained on the server from the request. In itself, it is also not unique, since it can coincide with many.
3. Record statistics and leave a mark in cookies or ls so that nothing more is recorded from this user.
4. Record statistics after being on the page for more than a certain time. So that a simple opening of the page by a bot or otherwise does not wind up the counter.
Can you please tell me the best way to count page visitors? What approaches are applicable here?
Answer the question
In order to leave comments, you need to log in
First we need to decide what we think.
And why.
Without this, it is pointless to start any task.
If you need to hang a meaningless counter "how many times the article was viewed" on the page, then it's stupid every time you open it and don't sweat it.
If you are interested in some meaningful statistics, then formulate a problem and select a solution for it.
Set up a counter from mail.ru/liveinternet, etc. You won’t do it better anyway - the task is non-trivial and full of nuances.
depends on what you want to get. and it’s impossible to make it ideal because there is no clear boundary between who is a bot and who is not a bot, the second request from the same SP is again I logged in or my sister from our common router.
but in general, I would recommend this:
1) popular bots can be filtered out by user agents (probably there are ready-made libraries).
2) blocking while keeping in memcache for 30 minutes ip+id_str (or for example md5(ip + id) ) - simple and effective protection against F5.
3) optionally, you can do as in p4 - after N seconds, send a request to update the counter. if someone has a task to wind it up, they will immediately pull it, so at least protection by SP (n2) is needed.
but if someone has the task of cheating, then finding a proxy is not a problem, you will not protect it in any way if you do it without any registrations.
another recommendation - if the counter is displayed on the pages - cache the counter for some time to make it more difficult for attackers to learn how it works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question