I don't record that by myself, instead I'm using Google Analytics who provides that and many many more useful info .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script language="javascript"> var seconds = null; function timer( ) { seconds++; setTimeout( 'timer()', 1000 ); } function tellUser( ) { alert( 'Thanks for visiting, you viewed this page ' + seconds + ' seconds' ); } </script> </head> <body onunload="tellUser();"> <script language="javascript">window.onload=timer();</script> </body> </html> HTML: You could do it like that, only instead of alerts use ajax and php to update a database or write to a file