SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Glasgow
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    recording user access

    I have a site that requires user login before they can access the website.

    I want to know how I can record the date and time that users access the site and the duration.

    Any ideas?

    Thanks,
    S

  2. #2
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,198
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    You should just create a database table where you will input the time the user logged in, and then store the id of the row in a session variable.

    Then for each time the user request a page you should update the row with the last "accessed" time.

    That is the only way to find out how long the user was on the site, as php is executed on the server side, there is no way to accuratly state when a user goes offline. Hence you need to update the row each time they request a page instead.

    You can write a javascript code which would contact your server when the window is closed, however this only works in teory. In practise it does not work too good, buggy browser support, users having several windows open would logout several times etc.


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
  •