Counting Unique Visitor

ⅰ亾dé卋堺 提交于 2019-12-13 17:39:21

问题


  • I want to count unique visitors and show them to visitors.
  • I don't want to use any 3rd party tool (like analytics or something else)

What is a unique visitor exactly? Does the REAL unique visitor changes with IP, cookie or MAC?

I've though this way:

  • Get visitors IP adress
  • Search it from database
  • If exists, don't do anything
  • If not, insert IP adress and server time to database and add this to count

Is this way right? Should I use cookies or get MAC adresses too? BTW all these things -getting information, store it, compare it- legal?

And one last question. Can I do all these things WITHOUT database? Only with using JS, PHP and text files or something else?


回答1:


IP and MAC are not good ideas, because:

  1. Many users can share the same IP address, e.g. when behind a NAT.
  2. You have no way of accessing the MAC address of the client, unless you have special software (not an ordinary HTTP server) and you operate on a LAN. Or you exploit some security bug in browser, but that does not count ;)

Setting a cookie with a uniquely generated value is a good idea, but be aware that cookies can be turned off and erased by the client. As of legality, as long as you declare the usage of cookies and you don't do evil things (counting unique visitors is ok), you are safe.

If you assume that a client with no cookie is a new visitor, then you don't need neither a database nor a unique value in the cookie, simply check if the cookie is present or not and set it. If you want to get more information, then, yes, you will have to keep track of unique values in cookies.



来源:https://stackoverflow.com/questions/19754934/counting-unique-visitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!