Search code examples
phpbrowseruser-agentdetect

How to recognize 2 PCs with same IP and browser(version)


I want to give a "like" option on my page for non-logged users.

The simpliest thing would be to detect user IP ( e.g. by $_SERVER['REMOTE_ADDR']).

More sophisticated would be detecting user's agent (e.g. by $_SERVER['HTTP_USER_AGENT']).

But I want to give like-posibility for "each PC in family" (real-life family) - this could also mean they all have not only the same IP, not only the same browser but also the same browser-version...

So how would I determinate whether it is a different PC? (without using cookies/session)

I want to store one "like" per PC and since cookies can be cleared I didn't want to use them :)

I wanted to abstract my particular interest from the whole problematics - so I did.
However you should never trust user input (as David pointed out) - so do not base your final like-count on just that ! At least put a likes/per IP limit and combine it with cookies/session.


Solution

  • Your only option to do this outside the simple methods of using cookies, logins, etc. is to do browser fingerprinting. This technique involves gather a variety of information that the browser outputs to the server/webpage and making a hash of it to create a unique ID for that client. It has a remarkably high accuracy and would work fairly well under the circumstances you are describing.

    It is based on the idea that "no two browsers are exactly the same". In other words, you look at screen resolution, user agent strings, active plugins, etc. and create a "fingerprint" of those settings. There is almost always going to be a variance in some way.

    There are available libraries that can help get you started. Here is one that is very easy to implement and understand... https://github.com/Valve/fingerprintjs