Re: Tracking visitor times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 18, 2007 6:05 AM, Zoran Bogdanov <test1.test1@xxxxxxxxxxx> wrote:
> Hi,
>
> Is it possible to track how long has a single visitor been on my site?
>
> example: I go to www.somesite.com at 5.am and I exit the page (close my
> browser or just go to another site) at 6.am. How do i track that 1 hour
> period using PHP?
>

If you just want to track a single visitor, it might be easiest just
to hire someone to go sit and watch them. :-)  (Sorry -- I'm running
on little sleep and couldn't resist.)

Most often the stats packages that show how long a user visits a site
do so by examining the server's log files and looking for the last
page request by a particular user and the first request by the same
user and subtracting. You can do the same by checking whether a
session variable (or cookie) exists on every page and, if it does not,
set that session variable equal to the current time stamp. Then on
each successive request you could calculate how long it has been since
they first visited your site. If you need to report on the time later,
you'll need to store the times of each request to some persistent
location, which is what the log files are doing. If you have access,
you could read them; otherwise you can build your own log in a file or
a database.

Now, this won't tell you that after opened the last page I visit on
your site I spent another 20 minutes viewing your content. For that
matter, it doesn't guarantee that I actually read anything on your
site at all -- just that I requested some pages and that the time
between my first request and last request was one hour in your
example. If you really need to know when I "close my browser or just
go to another site" you'll need to add some JavaScript to send another
request when the browser leaves your site.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux