I'm following solution #1 of this answer. After a while, there will be some redundant rows in the table. Suppose this table:
// cookies
+---------+-------------------------+------------------+------------+------------+
| id | email | cookie | date_time | device |
+---------+-------------------------+------------------+------------+------------+
| int(11) | varchar(50) | varchar(128) | int(11) | |
+---------+-------------------------+------------------+------------+------------+
| 1 | [email protected] | ojer0f934mf2... | 1467204523 | |
| 2 | [email protected] | ko4398f43043... | 1467205521 | |
| 3 | [email protected] | 34fjkg3j438t... | 1467205601 | |
| 4 | [email protected] | 0243hfd348i4... | 1467206039 | |
+---------+-------------------------+------------------+------------+------------+
So the email
column isn't unique and each device has its own row.
My question: How can I fill the device
column? Do I even need to detect the user's device or should I handle it another way?
Why do I need to determine devices? Since when a user removes their browser's cookies, then my website identifies them as a new user and creates a new row for them into table above. So after a while, there will be some redundant rows in the table.
For example: Imagine peter
has only two devices (laptop, phone). And he has two rows in the table above. He removes his browser's cookies and logs in. What happens? My website creates a new row into table above. Now peter
has 3 rows in the table above (while he has just two devices). So surely one of those three rows is redundant. That's why I need to detect devices to remove redundant rows.