I would like to prevent a script from repeating when a user refreshes a web page. 

currently, I have a php header file that calls a mysql script that inputs the time a user logs in into my DB. I have noticed that on page refresh, the script is ran again, updating the DB with the time of refresh. This defeats the purpose of obtaining the time of login. The ultimate goal is to determine the length of time a user remains on my site. Is there a better way to go about this? 
right now, I am just using the NOW() mysql function to insert the date and time into the DB. 

Thank you