最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to identify a visitor based on their browser characteristics? - Stack Overflow

programmeradmin3浏览0评论

I'm making a simple application where users can rate items.

I want to make the application very easy to use and would like to avoid a login, even if it means less accurate ratings.

I found this article on recognizing a user based on browser characteristics: /?fa=Articles.showArticle&art_aid=128563

How can I implement something like that in JS/Node.js?

I'm making a simple application where users can rate items.

I want to make the application very easy to use and would like to avoid a login, even if it means less accurate ratings.

I found this article on recognizing a user based on browser characteristics: http://www.mediapost.com/publications/?fa=Articles.showArticle&art_aid=128563

How can I implement something like that in JS/Node.js?

Share Improve this question edited May 19, 2011 at 15:33 jcolebrand 16k12 gold badges77 silver badges122 bronze badges asked May 19, 2011 at 15:20 edtedt 22.4k32 gold badges85 silver badges119 bronze badges 6
  • Browser based recognition involving details of a browser must be done at the browser, not at the server. The browser won't tell you everything in HTTP headers. – jcolebrand Commented May 19, 2011 at 15:33
  • 9 @edt Have you heard about or tried evercookie ? – LazyOne Commented Jul 6, 2011 at 0:18
  • 2 @LazyOne +1 because holy crap, evercookie is terrifying in its destruction of privacy. – Chris W. Commented Jul 7, 2011 at 22:51
  • It's even easier to open another browser than to delete cookies. – Litek Commented Jul 11, 2011 at 16:35
  • It's impossible to identify individual users without a login. My home is a simple example why not: several family members browse the web with the same browser on the same computer hooked up to the same ISP. – nnnnnn Commented Jul 12, 2011 at 6:39
 |  Show 1 more comment

5 Answers 5

Reset to default 15

Rather than doing a lot of trickery based on browser characteristics which may or may not be available, you could just use a cookie. Browsers may change/upgrade over time. You won't be able to avoid a browser change causing a new user in either case. But, a cookie will be maintained over browser upgrades. Just set the cookie to some (semi)unique value (such as time including milliseconds + IP address) and you'll be all set. At the point that you have so many users that the (semi)unique values have issues, you'll be rearchitecting your site anyway (and probably have a team of people working for you).

If for some reason you want to avoid cookies, you could use PHP to get the client's IP address:

<?php
echo ' Client IP: ';
if ( isset($_SERVER["REMOTE_ADDR"]) )    {
    echo '' . $_SERVER["REMOTE_ADDR"] . ' ';
} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    {
    echo '' . $_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    {
    echo '' . $_SERVER["HTTP_CLIENT_IP"] . ' ';
}
?> 

You could add a function that asks for a user name if the ip address isn't on file, and associate the new IP with old user names, etc. Cookies work much better, of course :)

Another option, easier than cookies would be localStorage:

Give the client a UUID:

localStorage.setItem('user',UUID);

Get client's UUID:

localStorage.getItem('user');

This is a bit better than using cookies, for example in Firefox (as per MDC):

  • DOM Storage can be cleared via "Tools -> Clear Recent History -> Cookies" when Time range is "Everything" (via nsICookieManager::removeAll)
    • But not when another time range is specified: (bug 527667)
    • Does not show up in Tools -> Options -> Privacy -> Remove individual cookies (bug 506692)
  • DOM Storage is not cleared via Tools -> Options -> Advanced -> Network -> Offline data -> Clear Now.
  • Doesn't show up in the "Tools -> Options -> Advanced -> Network -> Offline data" list, unless the site also uses the offline cache. If the site does appear in that list, its DOM storage data is removed along with the offline cache when clicking the Remove button.

but it only works with HTML 5.

I agree with evan it is much easier to do it using cookies.

if you would like to write something like that you would need to get data from the server and from a browser like (ip,browser,flash,java,cookies...): weight this data , create rules of changes like browser upgrades flash upgrades which would increase or decrease the weights, than create neuron neural network , gather loads of training data and teach your network. (You could take other approach not using Neural networks)

This is a nice project but it seems to be like using a Tank or a Battleship to kill a mouse

I think that the difference between using simple cookies and this browser characteristics gathering would be around 10% so go for cookies.

You can take a look here: http://www.w3schools.com/js/js_browser.asp

But i strongly recommend using cookies for this purpose. Also keep in mind that cookies may be modified by the user. If you can - just use something like a PHP $_SESSION

I would look for particular object detection in js instead of browser sniffing... check this link out

发布评论

评论列表(0)

  1. 暂无评论