简体   繁体   English

PHP-获取唯一ID

[英]PHP - Get an unique ID

I am using php and I want to get a System's UNIQUE ID. 我正在使用php,我想获取系统的唯一ID。
I can't use $_SERVER['REMOTE_ADDR'] since all machines have the same local IP address (127.0.0.1). 我无法使用$_SERVER['REMOTE_ADDR']因为所有计算机都具有相同的本地IP地址(127.0.0.1)。 Is there anything else I could use? 还有什么我可以用的吗?

You won't reliably be able to obtain a MAC address from an end user. 您将无法可靠地从最终用户那里获取MAC地址。 You can't use the hostname because the hostname exposed is based off of the IP address and they are all connecting through the same IP. 您不能使用主机名,因为公开的主机名基于IP地址,并且它们都通过同一IP连接。

The only other way I could think of doing this is using a cookie or authentication. 我想到的唯一其他方法是使用Cookie或身份验证。 If they authenticate, then you use their user ID. 如果他们进行身份验证,那么您将使用他们的用户ID。 If not, then you can set a long term cookie with a uniquely generated ID. 如果不是,则可以使用唯一生成的ID设置长期cookie。 For instance: 例如:

if (empty($_COOKIE['machine_id'])) {
  $id = md5(uniqid(rand(), true));
  setcookie('machine_id', $id, time()+(3*365*86400));
}

Then this client would need have a unique identifier for future connections in the machine_id cookie. 然后,此客户端将需要一个唯一的标识符,以便将来在machine_id cookie中进行连接。

This would be dependent on a client enabling cookies and not clearing their cookies. 这将取决于客户端启用cookie而不清除其cookie。

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

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