phpvisitor-statistic

How to count number of real visitors on a specific page using PHP


How can I count only the real visitors (i.e. not crawlers, bots, etc.) of a specific page on my website using PHP?

I want to do it as accurate as possible, e.g. the way Stackoverflow counts the the visitors of a specific question.

I currently increment the page counter field in the database for each visit, but that gives unrealistically large numbers of visitors for each page after just a few days. I guess it counts crawlers, bots etc,. and even some browsers hit a page multiple times.


Solution

  • I'm not sure but many bots doesn't execute javascript. You can try to send the visit count by using ajax after the page is loaded. Als store the user IP and user-agent to prevent most duplicate counts. Also many bots has ther own user-agent so you can also check that.

    Maybe also this question can help you How to recognize bots with php?