简体   繁体   English

在PHP中获取唯一的Web浏览器ID

[英]Get Unique web browser ID in PHP

I am looking a way to store unique ID of web browsers in PHP ? 我正在寻找一种在PHP存储Web浏览器的唯一ID的方法? I searched everywhere..but couldn't find any useful things. 我到处搜索..但找不到任何有用的东西。 First of all, does web browsers have a unique ID or something like that to identify them??? 首先,Web浏览器是否具有唯一的ID或类似的东西来识别它们? Like the computers have a unique IP address, does browsers have anything like that?? 就像计算机有一个唯一的IP地址一样,浏览器是否有类似的东西? I am trying this so that I can store user details into my database. 我正在尝试这样,以便我可以将用户详细信息存储到我的数据库中。 So, we can find out a user used which browser to access my PHP website. 因此,我们可以找到一个用户使用哪个浏览器来访问我的PHP网站。 Can I store such an ID to a php variable? 我可以将这样的ID存储到php变量吗?

for example, $x= ID of the web browser. 例如, $x= ID Web浏览器的$x= ID

When a user visits your site you know his IP, browser, OS and other stuff. 当用户访问您的网站时,您会知道他的IP,浏览器,操作系统和其他内容。 You need to know if the next time the same user visits you (same IP, same login perhaps) is using the same browser. 您需要知道下次同一用户访问您(相同的IP,可能是相同的登录)是否使用相同的浏览器。 This can be achieved in two ways: 这可以通过两种方式实现:

a) Create a cookie, store it in the browser and in your DB, then compare every visitor that has that cookie against your existing cookie table to identify him. a)创建一个cookie,将其存储在浏览器和数据库中,然后将具有该cookie的每个访问者与现有的cookie表进行比较以识别他。 If the cookie has a very long expiration time it won't be lost across sessions, and will be unique to each browser. 如果cookie具有非常长的过期时间,则它不会在会话中丢失,并且对于每个浏览器都是唯一的。 But it will be lost if the user clears cookies. 但如果用户清除cookie,它将丢失。

b) Store a string in the browser's local storage. b)将字符串存储在浏览器的本地存储中。 This works pretty much the same as the cookie method but there's no expiration date for the data, and it's thougher to remove it than to clear cookies. 这与cookie方法几乎相同,但数据没有过期日期,删除它比清除cookie更难。

There are other methods, like combining different kind of cookies to provide redundancy. 还有其他方法,例如组合不同类型的cookie以提供冗余。 I remember a project called Evercookie that did something like that. 我记得一个名为Evercookie的项目做过类似的事情。 I believe it's pretty much abandoned now. 我相信它现在已经被抛弃了。

You can use the browscap library and then make an md5 of the browser information: 您可以使用browscap库,然后制作浏览器信息的md5:

Uses GaretJax/phpbrowscap 使用GaretJax / phpbrowscap

$bc = new \phpbrowscap\Browscap('data/');
$current_browser = $bc->getBrowser(null,true);
$str = json_encode($current_browser);
$browser_id = md5($str);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM