Jump to content


Tracking users Offline Online status


1 reply to this topic

#1 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 06 July 2007 - 05:28 AM

Hi there,

I'm writing PHP code to track users on my website.
Small situation sketch:

When a users enters the website a unique sessionID is made and saved in the: Session, Cookie and MySQL database.
I can track the current page a user is on by logging the $_SERVER['REQUEST_URI'] in the database on every page visit.
Now when a user logs in their userID is entered in the Sessions table so both these tables are Related by the username


By doing this I achieved logging in and tracking the user page.
My problem now is I want to see the offline/online status for users.
Since my cookies are 3600 seconds valid the user will stay 'logged in' for an hour, no matter if he/she leaves the page.
I don't want to shorten that period since users will have to log in again if they stayed inactive too long.

To get to the point:

How can I see when a user closes his/her browser and is it possible to then quickly send a AJAX request to the server to let him know the user went offline

Or any other way to log off a user without him/her clicking on 'Log Off'...



Thanks in advance

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 06 July 2007 - 09:03 AM

Well you can give the onunload function a whirl in Javascript. Weather it will have enough time to run or not is another question.

You can either try to use the window.onunload and re-direct them to your logout page quickly which is plain and simple and does a quick logout, or you can run an ajax call.

A different option is to just run a cron job every hour, see which sessions are over an hour old and mark them as logged out.

Matt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users