How can I detect user's device?
<p>I'm trying to create a system which keeps the user logged in <em>(something like remember me checked)</em>. Ok I have a table like this:</p>

<pre><code>// cookies
+---------+-------------------------+------------------+------------+------------+
|   id    |         email           |     cookie       | date_time  |   device   |
+---------+-------------------------+------------------+------------+------------+
| int(11) |      varchar(50)        |   varchar(128)   |  int(11)   |            |
+---------+-------------------------+------------------+------------+------------+
| 1       | jack_2009@gmail.com     | ojer0f934mf2...  | 1467204523 |            |
| 2       | peter.zm@yahoo.com      | ko4398f43043...  | 1467205521 |            |
| 3       | matrix_john23@gmail.com | 34fjkg3j438t...  | 1467205601 |            |
| 4       | peter.zm@yahoo.com      | 0243hfd348i4...  | 1467206039 |            |
+---------+-------------------------+------------------+------------+------------+
</code></pre>

<p>As you see, this user <code>peter.zm@yahoo.com</code> have logged in by two different devices:</p>

<pre><code>| 2       | peter.zm@yahoo.com      | ko4398f43043...  | 1467205521 |            |
| 4       | peter.zm@yahoo.com      | 0243hfd348i4...  | 1467206039 |            |
</code></pre>

<p>So <code>email</code> column isn't unique and each device has its own row.</p>

<p><strong>My question:</strong> How can I fill <code>device</code> column?</p>

<hr>

<p>Why do I need to determine devices? Because when an user removes his browser's cookies, then my website identifies him as a new user and creates a new row for him into table above. So after a while, there will be some redundant rows in the table. </p>

<p>For example: Imagine <code>peter</code> has just two devices <em>(laptop, phone)</em>. And he have two rows into table above. Ok, he removes his browser's cookies and logs in. What happens? My website creates a new row into table above. Now <code>peter</code> has 3 rows into table above <em>(while he has just two devices)</em>. So surely one of those three rows is redundant. That's why I need to detect devices to remove redundant rows.</p>