Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Online User

Hello, whit the help of a Ajax course that explains using ajax to create a status online or offline users i would like to combine it whit php, and what im trying to achieve is in creating a list of users that shows in real time if there online or offline, is there a php function that checks if a user created a session or somethign? Or i have to create a table to controlo time and date the users login and logoff?

Can someone guide me the best way?

2 Answers

I think somewhere in your data model, there needs to be a list of logged in and logged out users. But then you have the issue of the user not logging out (clicking the logout button)- I never log out of teamtreehouse, I just close the page, so this data model would show me as 'logged in' all of the time! Maybe there's a way to count all of the active sessions you have - seeing as they're stored server side.

There must be a function in either php or javascript, which callsback when the user closes the window? ... But then what if they have multiple windows of the same application! Agh!

Maybe you could combine a couple of functions to decide if the user is active or not, like timeouts etc..

If you find an answer off of treehouse, I'd be interested to know how you managed this!

i believe you can use

session_set_cookie_params(0);
session_start();

If I remember right session_set_cookie_params(0) basically means until the window is closed. This should delete the session cookie when the window is closed, but I am not sure how you could then find out which sessions are active or not.

I've been looking around google and inactivity for 10 minutes seems to be a common decider us the user should be classed as logged off. Here's one example: http://www.plus2net.com/php_tutorial/whois-online.php

Coupled with the session_set_cookie_params(0), this might work