PHP convert time passed into integer, long or a number based value
What I am trying to is keep track of the amount of time a user views something overall. I am trying to figure out a way to convert everything into an integer. I am thinking about converting everything to nano seconds (days, hours, minutes), add the nano seconds together from another time,开发者_如何学C and then use that as a total time elasped.
Is there a better/easier way?
Probably a sensible approach would be the way microtime() handles it: two integer values, one counting microseconds and one counting seconds. (Just counting microseconds or nanoseconds risks overflowing PHP's 32-bit integers.)
The thing returned by mktime(...) and time() are already an integer number of seconds.
Simply store time() in a form when you send it, and take it away from time() when you recieve it back in the POST.
If you are trying to time between different page reads, then store the time() value in the $_session variable.
You won't be able to get a time for the last page view. Even if you try to intercept the unload event and send something from that it will not alwasy work (browser locks, network problems, etc).
精彩评论