문제

  • 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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top