This script passes the time in a QueryString parameter. You could just as
easily store it in a session variable, log it to a database, or write it to
a text file. It all depends upon what you intend to use the information
for.
Have you ever been curious about how long it takes someone to fill out a
form? What about how long they took to read a page? Well with a little
bit of code we can easily determine this type of information.
Here's what we need. First when they get to the page that we are curious
about we need to store the time at which they retrieved the page. Next,
when they send in their next request, we need to get back that value and
compare it to the stored time. The result is the time between their two
page requests. It's not perfect, but basically we have a quick and easy
instant timer.
Darn! You caught that thing about it not being perfect didn't you? Well
here's what's wrong with it. First the actual time isn't that precise due
to the fact that it's generated by the server, not by the client after they
get the page. Next we have the problem that we don't always get the result
back if they close their browser or type in a new URL, so we probably don't
want to depend on the value too much. Last, but not least, someone could
get your first page, go out to dinner, come back and then finish filling
out your form. We can't tell what they were doing during the time they had
the page open. If you can live with these conditions, this script makes a
great little addition to your scripting library for use in those instances
where you 'just want to get an idea' of how long people are spending on a
specific page.
Like many of our samples, this one leaves a lot to be desired. It doesn't
log its results anywhere. (See the database and text file samples for
that type of code.) It could also store these values in a session variable
so you'd have access to them if you wanted to use them for anything else.
The implementaion of these ideas as well as any others are 'left as an
exercise for the reader' as my calculus book used to say (at least about
the things the authors couldn't figure out).