问题
- 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:
- Many users can share the same IP address, e.g. when behind a NAT.
- 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