-1

I want to generate unique number for each of my site users. How can I achieve something like this using JavaScript?

P.S: I also want this unique number have information about users for example something like IP or concatenation something with IP. Can I have user IP using JavaScript?how?

pooya
  • 881
  • 2
  • 13
  • 29

1 Answers1

2

Generating a guaranteed unique number for every site user cannot be done purely at the browser. The only way to guarantee a unique number for every site user is to generate the unique number at the server and give that to the browser (either in the original page or via an ajax call or via a post/get).

If you want a statistically unlikely to be the same number that isn't 100% guaranteed, then you can use a time number plus a random number or a very, very long random number and have a statistically unlikely to be the same number, but not 100% guaranteed to be unique number.

There is no way that I'm aware of to get the IP address from pure client-side javascript without asking a server and, even if you could, because of proxies, NAT, firewalls, etc... IP numbers are not guaranteed to be unique or constant for a given user either. For example, all the users in my home all share the same outgoing IP address.

jfriend00
  • 580,699
  • 78
  • 809
  • 825