Make use of the $_SESSION
Variable:
$_SESSION['timestamp'] = time();
Duration can be calculated with a simple mathematical operation. Your code (might) look like this:
$_SESSION['initial_timestamp'] = time();
$_SESSION['timestamp'] = time();
$_SESSION['duration'] = $_SESSION['timestamp'] - $_SESSION['initial_timestamp'] ;
This (should) calculate the time of the logged in user since his first log in