JavaScript Unique Browser Id
is there anyway to create a unique ID for a browser within javascript?
Im not talking about an ID that is random everytime it is generated but an ID that is unique to the browser it is generated in but also takes into account the computer its running on.
Example:
Windows 7 Chrome might generate: asdh128hakj4gh
Windows 7 Oper开发者_StackOverflow中文版a might generate: 23hjad823hjakk
Windows 7 Chrome, diff hardware, might generate: asd238881jaal
etc...
Is there anyway to do this?
What you are looking for is called Browser Fingerprinting.
You can google for some open source libraries. Ex: fingerprintjs2
Check out EFF's demo
Use cookies
and some unique hash into its. (Each browser has own cookie jar, even if on computer is many browsers)
You can use biri library. The ID is generated per computer, and doesn't change unless the MAC address of the computer changes.
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
if (Sys.ie) document.write('IE: ' + Sys.ie);
if (Sys.firefox) document.write('Firefox: ' + Sys.firefox);
if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
if (Sys.opera) document.write('Opera: ' + Sys.opera);
if (Sys.safari) document.write('Safari: ' + Sys.safari);
With these code you can get the type and the version of the browser, and the value should be unique according to different browser , if you want to generate other unique ID base on it , then use it
How about the MD5 of the UserAgent + ClientIP + 'extrasalt'?
That will get you close but not perfect because it is possible for 2 clients to have the same IP (using NAT) and exact same UserAgent (tightly controlled IT department = same deployment, or just luck).
What it looks like you are trying to do is some kind of licensing? So that only so many browsers can be registered to use your app?
Unfortunately there is no way of reading the users computer hardware setup. As one answer says you can store a cookie on the machine but it can easily go missing.
If you were restricted to using old IE browsers you could use ActiveX to read computer hardware: http://www.devarticles.com/c/a/JavaScript/How-to-Use-JavaScript-for-Hardware-Knowledge/
精彩评论