Possible to count time with PHP?

Discussion in 'PHP' started by jpigford, Dec 13, 2005.

  1. #1
    I'm not sure my subject really does a good job of explaining what I'm asking here, but what I'm doing right now is each time someone accesses a certain page I track it in the database so I have a count of how many times that page has been accessed. But what I'd like to do is not actually count that a particular page was viewed until the user has been on it, say, 8 seconds.

    How could I pull that off?
     
    jpigford, Dec 13, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use 'onload' to start some javascript running when the page is loaded.

    After 8 seconds the script can use AJAX to make a call to an sql database logging the hit.
     
    dave487, Dec 13, 2005 IP
  3. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #3
    log the session id and the time the person first enters the page.
    whenever they go to another page, log the new time and compare the two, if the time is greater than 8 seconds, then record that the previous page has been visited. Overwrite the first time recorded with the new time and repeat the cycle. The flaw with this system is that it wont record the last page viewed as been viewed...

    If you're using AJAX, I suppose you could have a javascript time counter that coutns to 8, then records the page as been viewed...
     
    relixx, Dec 13, 2005 IP
  4. jpigford

    jpigford Peon

    Messages:
    114
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am using some AJAX in places...hmm...that could work.
     
    jpigford, Dec 13, 2005 IP
  5. HN Will

    HN Will Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If all you're doing is tracking - then scrap your logs for this info and speed up your site.
     
    HN Will, Dec 13, 2005 IP
  6. jpigford

    jpigford Peon

    Messages:
    114
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Not just tracking, I'll be displaying info on the site as a result of it.
     
    jpigford, Dec 13, 2005 IP