Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP visitor statistics

    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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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
    Why not thank me?

    http://adamsworld.name

  • #4
    New Coder
    Join Date
    Apr 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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
    Why not thank me?

    http://adamsworld.name

  • #6
    New Coder
    Join Date
    Apr 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your kind offer Adam.
    I'll PM you if I can't solve this one by myself.

    Tony


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •