Identify Local Pc With Jquery
Solution 1:
No device or browser can return a unique Id. It would be a means of security breach. None the less it is a great question and many apps create a uuid that is stored on the device so that it can be identified, if at least on their server.
This is how you do it
http://jsfiddle.net/dq5oy6w2/1/
var uuid=function(){
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return u;
}
var getDeviceId = function(){
var current = window.localStorage.getItem("_DEVICEID_")
if (current) return current;
var id = uuid();
window.localStorage.setItem("_DEVICEID_",id);
return id;
}
document.getElementById("deviceid").innerHTML=getDeviceId();
Here i use localStorage, it's fast reliable but the user can clear it on most devices. If you want something more robust, consider indexedDB or WebSql -both are harder in some respects to clear.
Since you have the ip on the server you could pass this id in your server call, and have the IP as a fallback, if you store this uuid with the IP, on your server: you could have a means of replenishing the client, if it looses the uuid. But that may restrict multiple devices on one IP.
Post a Comment for "Identify Local Pc With Jquery"