views:

408

answers:

3

Could you suggest an efficient way to identify a unique user with javascript (e.g. calculate an hash to send to the server side)?

EDIT: The point is that I can't 'intrude' into the browser (e.g. send cookies). And IPs are also not the option. And it has to be a client-side solution (therefore javascript).

+4  A: 

A common solution to this problem is to calculate a unique ID on the server side, then push a cookie to the browser containing that ID (checking, first, to see whether that cookie has already been defined for the current browser).

Advertising networks use that technique fairly heavily to gather demographic information on web users.

EDIT By the way, the "unique ID" can simply be the first session ID associated with the user. Many frameworks can supply that for you.

Brian Clapper
A: 

A "unique" string could be the user's IP address, but beware that different users behind a corporate firewall, for example, could appear with the same IP.

The IP address of user is already available at server level, you don't need js.

friol
+4  A: 

I upvoted Brian's answer but I'd like to add that the problem is identifying a unique user. Insisting that it be done in Javascript - which is stateless beyond the page level unless there is participation at the server level - just isn't a fruitful approach.

Mark Brittingham
Yes, and the identification using a cookie isn't guaranteed to last. People can delete cookies. However, in the aggregate (i.e., with large numbers of visitors) and over time, the technique can be used to gather significant information about one's visitors.
Brian Clapper