...

View Full Version : PHP visitor statistics



tonytiger
07-20-2007, 11:40 PM
Hi,
I'm working on a web page and I would like to collect information about the visitors. The web page is a picture gallery and it will contain three different pages: index.php, category.php and image.php. Index.php is the main site, category.php shows some category of pictures and image.php shows an individual image.

I know how to collect ip-addresses and such, but what I would like to do is the following: Regardless of which of the above mentioned pages the visitor first visits a log will start. As the visitor browses through galleries and images some information is collected. As a result I would like to have log which contains the user information and which pages user has browsed. For example:

IP=xxx
category.php->open.php->index.php->category.php

I could do the following: As user enter, a log starts identified by IP. Each time the Referer-address of the same IP is any of the three pages, collect information.
The problem is that I don't know how when to close the log? That is, I don't know when the user has left my site. Is there a way to know this or some other standard solution to my problem?

Thank you in advance.

Tony

mlseim
07-21-2007, 03:10 AM
The collecting part is easy, using PHP sessions.

Knowing when they leave is hard. You can count how many
sessions are open (how many are online), but they can leave
and still have the session open (until their browser closes).

If you owned your own server, there might be a C++ executable
that does it behind the scenes, but I can't find anything that
does this on a remote server.

See what others might say about this ... I'm not an expert on server stuff.

GO ILLINI
07-22-2007, 07:14 AM
you could have a script or cron that checks the session every 2 or 3 minutes for activity. Of course this is not foolproof because they could read a page for 5 minutes or something, but it will be the most accurate way without installing something on the client machine. You could even make it so that after the 2 minutes if another page is accessed within 10 or 15 minutes to erase the time they "left" the website so that the cron can come by again and set it.
Hope that this wasn't to confusing...

-Adam

tonytiger
07-22-2007, 01:45 PM
Thank you both for answers.
GO ILLINI, using a cron seems to be a good idea. Can you tell a bit more specifically how to do it in practice? And will the user be able to see it?
You also talked about 'activity'. Actually, I would be satisfied if I only new if the user is still on the page or not.
Hope we are talking about the same things =)

Tony

GO ILLINI
07-23-2007, 04:35 AM
Cron: http://www.adminschoice.com/docs/crontab.htm
You can cron a php file.

You see... you need to check 'activity' because there is no way to tell when a user leaves a page if he is also leaving your website. The cron will need to run every 5 minutes and will check a mysql database/session files for the last time a user opened a page. If that time is over 5 minutes consider that this is the time that they left your website.

The php on the pages will need to edit the database to say when the pageload and their IP or some other unique identifier. This would also update if the user loaded another page on your website, therefore extending the session.

If you are not sure what to do with the code, you could PM me and we could work something out. The easiest way to do it would be with mysql to log IP, start time, and closing time.

-Adam

tonytiger
07-25-2007, 03:29 PM
Thanks for your kind offer Adam.
I'll PM you if I can't solve this one by myself.

Tony



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum