SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast AimyThomas's Avatar
    Join Date
    Sep 2011
    Posts
    46
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Need a tracking PHP Script – “how long people stay on the website?”

    I want to know, is there a way to track how long anyone has been logged into website and then insert it up for each time they have logged on.

    In case, user a logs in for 30 minutes, then later comes back and logs in for an hour, then later comes back and logs in for 50 minutes,

    Add it up equal 2 hours 20 minutes. Is this possible?

    Thanks

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,019
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    If you're storing the sessions in the db then you could have a field in the session table which would be a timestamp (set when the user logs in) and then when either the user logs out or their session expires, the elapsed time between when they logged on and when they logged off would be calculated and added to the relevant field in the user table
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    You'll need a cronjob (or equivilant) to do the end-time though, since there isnt a callback on session expiry.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Just because a session expires after 'x' hours doesn't mean that the person was actually on the site all that time. They may have only been there a few seconds and then forgot to log off leaving their session to expire based on settings on the server.

    If they have javaScript enabled then you could set up a script on the page that calls the server at regular intervals to advise that they are still on the site. You would then know that they had left when more than that amount of time passed without the script making another call.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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