I need to take the time that the user was on a particular page, and the user to leave the page, this time be registered in the database.
Would anyone have any idea how to do it?
[Edited]
The time I was able to catch using javascript. The problem is to record this access time in the database. I tried to use the following code to send access time via POST and then capture and insert via mysql, but it did not work:
<form action="post" id="register_access">
<input type="hidden" value="1" name="access_time" id="access_time"/>
</form>
<script>
var contador = 0;
setTimeout(temporizador,1000);
function temporizador() {
if(contador < 10000000){
setTimeout(temporizador,1000);
}
document.getElementById('access_time').value = contador;
contador++;
}
jQuery(document).ready(function($){
$(window).on('beforeunload', function(e) {
$('#register_access').submit();
//return 'Are you sure?';
});
});
</script>