I have a table on my database called ‘Log’. This Log table contains ID, Username, LoginTime and LogoutTime. That’s all.
It’s really easy to INSERT into ID, Username and LoginTime columns…
But dealing with LogoutTime, I was thinking there will be 2 condition :
-
User click logout button >> PROBLEM SOLVED, I can easily put INSERT script on my logout.php to handle LogoutTime column.
-
User just run away from my website by clicking close button of their browser >> THIS WILL CAUSE A PROBLEM. How can I write to LogoutTime column in this situation like this?
can it be handle by PHP only? I mean, doesn’t have to use jQuery… Thanks before.
You can implement something similar to this, the time can be different according to your need
But there is no way you can implement functionality 100% meet your requirements with php.
And with javascript you can try with
onbeforeunload, it is good practice than do it with javascript and not in php because of overhead reasons.