-1

I've a website and I want to track every user who visits my website.I thought using the IP address as unique id. The plan was very simple to get IP address sign-up to the database and store information. Then if user visits again a track system uses his IP Address to track his previous information and inserting new information, but unfortunately the IP Address is changing from time to time. How can I get unique something or static IP Address?

NightOwl888
  • 55,572
  • 24
  • 139
  • 212

2 Answers2

1

You can use the browscap library and then make an md5 of the browser information:

$bc = new \phpbrowscap\Browscap('data/');
$current_browser = $bc->getBrowser(null,true);
$str = json_encode($current_browser);
$browser_id = md5($str);
Rashed
  • 2,349
  • 11
  • 26
0

Just use cookies so user can decide if they want to get tracked on your site.

//generate unique id
$uniqid = bin2hex (openssl_random_pseudo_bytes (64));

//set cookie
setcookie ("cookie_name", $uniqid);

//--> now store uniqid in your database to identify the user.

//receive the cookie by next visit
$uniqid = $_COOKIE["cookie_name"]
wayneOS
  • 1,427
  • 1
  • 14
  • 20
  • Despite its name, `uniqid` is hardly globally unique and would be unsuitable for generating ids to track potentially millions of users over a long time. – deceze Apr 11 '18 at 07:31
  • @deceze you are right. i just wanted to show the cookie-part. I updated my answer to make the id more unique. – wayneOS Apr 11 '18 at 07:37
  • Still not much better. `md5` doesn't increase entropy, if anything it reduces it. You should use `random_bytes` or read from `/dev/urandom` or use UUIDs. – deceze Apr 11 '18 at 07:43