This is very similar to providing a Who's Online component to a website, which consists of the following:
First you have to have a MySQL table, lets call it Sessions (or whatever you want to call it; with at least a session_id column and a last_activity_date column, you can add additional columns)
Next you INSERT a record into this table storing the session id of the user session_id() and a date/time stamp (using MySQL function NOW()).
As the browse your site you update that record's last_activity_date column.
At the same time, you have either a cronjob running or a second query run on every page that queries the Sessions table checking for a date/time stamp that is more than X minutes ago.
Example: session_id 123456 last_activity_date reports 2012-10-04 11:00:00 and it is now 2012-10-04 11:15:00, so 15 minutes have passed with no interaction.
Now do whatever you wanted to do with those records.