Ender Graphix
Ender Graphix

Reputation: 47

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?

Upvotes: 0

Views: 420

Answers (1)

Devon Bessemer
Devon Bessemer

Reputation: 35367

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.

Upvotes: 1

Related Questions