简体   繁体   中英

PHP - Get an unique ID

I am using php and I want to get a System's UNIQUE ID.
I can't use $_SERVER['REMOTE_ADDR'] since all machines have the same local IP address (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. 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.

The only other way I could think of doing this is using a cookie or authentication. If they authenticate, then you use their user ID. If not, then you can set a long term cookie with a uniquely generated ID. 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.

This would be dependent on a client enabling cookies and not clearing their cookies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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