Automatically stop my timer

A few years ago I made myself a PHP/mySQL project timer that I use with the bits and pieces of web development that I charge hourly rates for. (My major jobs are charged by the project). I love it and use it all the time but I have one issue with it that is bugging me.

BTW, before you start berating me with “Why re-invent the wheel? There are dozens of timers out there already.”, I did it because it was fun, and it does what I want it to do and only what I want it to do. Except …

Sometimes when I’m in a hurry I forget to stop the timer and just shut down my browser and head off. As a result, the end-time does not get recorded and I have to go into the database and insert it by hand.

Is there any way this value can be automatically inserted into the “end_time” variable in the database if the browser is shut down before I remember to stop the timer?

Unfortunately, after the browser/tab is closed you cannot send an Ajax to the server so,
you cannot mark into your database; the onunload event will not work.

The only way to do this into a browser is to be annoying with yourself :slight_smile: Simple JavaScript:

<script>window.onbeforeunload = function(){ return true; }</script>

Else, create a desktop application (in C) that cannot be closed OR will be able to control the “close” action.

That’s a great idea. Thank you. All I need is a reminder to myself to stop and shut it down before I leave. Thank you.