Danny620 Posted September 1, 2009 Share Posted September 1, 2009 i like the idear of showing users online but i dont have a clue how to programming it maybe someone could point me in the right direction or send me some tut thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/ Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 Add a new field to your users table like: last_click_at DATETIME Then using the below query you can find which users are currently online (clicked in the last 5 minutes) SELECT * FROM users WHERE last_click_at BETWEEN now() - 300 AND now() Ofcourse this implies that you update this field on every click. Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/#findComment-910395 Share on other sites More sharing options...
Danny620 Posted September 1, 2009 Author Share Posted September 1, 2009 yes i think i understand but can u explain abit more like maybe and update page that updates that user Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/#findComment-910396 Share on other sites More sharing options...
kickstart Posted September 1, 2009 Share Posted September 1, 2009 Hi Doing this requires every page to update the user who has visited that page (probably in a common routine included at the top of each script). Eg, this routine, that also redirects people out of the system if they haven't done anything for X minutes (this is for Access SQL, but much the same for MySQL):- <?php $sSql = "Update AdminLogin Set LastRefresh = now() where Username = '".$_SESSION['Username']."' AND SessionId = '".session_id()."' and datediff('n',lastrefresh,now()) <= 60"; $resultSec = odbc_exec($Conn,$sSql); if ($resultSec) { if (odbc_num_rows($resultSec) < 1) { header('Location:Logout.php'); exit(); } } ?> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/#findComment-910402 Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 yes i think i understand but can u explain abit more like maybe and update page that updates that user Assuming a table structure like: CREATE TABLE users ( users_id INTEGER NOT NULL AUTO_INCREMENT, users_last_click_at DATETIME, PRIMARY KEY (users_id) ); Your update code would be: if (isset($_SESSION['users_id'])) { $id = abs((int) $_SESSION['users_id']);//set at login if (!$id) // do something: $id was 0 $query = 'UPDATE users SET users_last_click_at = now() WHERE users_id = %d'; $fquery = sprintf($query, $id); mysql_query($fquery/*, $db*/); } Your members online: $query = 'SELECT count(*) users_online FROM users WHERE users_last_click_at BETWEEN now() - 300 AND now()'; if ($result = mysql_query($query/*, $db*/)) { list($users_online) = mysql_fetch_row($result); } Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/#findComment-910410 Share on other sites More sharing options...
Danny620 Posted September 1, 2009 Author Share Posted September 1, 2009 thanks for that btw do u have Linux installed Quote Link to comment https://forums.phpfreaks.com/topic/172721-whos-online/#findComment-910412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.