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?
Asked
Active
Viewed 4,400 times
-1
-
3Easy, add a facebook widget :-) – jeroen Apr 11 '18 at 07:13
-
4IPs are not unique to users, not just over time, but *ever*. Set a tracking cookie. – deceze Apr 11 '18 at 07:13
-
1Try to research session management, cookies, browser fingerprinting – codtex Apr 11 '18 at 07:16
2 Answers
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
-
-
-
I've downloaded browscap library from github and uploaded it on my server but I don't know which file to include or require in order the library to work – Rainn Mohammed Apr 11 '18 at 09:39
-
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