quickstopman Posted May 14, 2007 Share Posted May 14, 2007 ok i have it so when you log in it sets the variable online to 1 , and when you log out its supposed to go to 2. but the problem is it doesn't go to 2 when you log out here is the log out page <? require 'config.php'; session_start(); $onlineid = 2; $offine = mysql_query("UPDATE `users` SET `online` = '{$onlineid}' WHERE id = '{$_SESSION['id']}'") OR die(mysql_error()); $_SESSION = array(); header("Refresh:2; url=default.html"); echo("You have Successfully Logged Out"); ?> any ideas why its not working Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/ Share on other sites More sharing options...
pocobueno1388 Posted May 14, 2007 Share Posted May 14, 2007 The problem with this method is some users <b>don't</b> logout at all. Instead of setting that number to 1 and switch it to 2, you need to make a timestamp in the database update everytime they click. Then on the online users page you just do a query that selects the users last active within the past x amount of time and display them. If you need me to go into detail on this I will, or someone else most likely will. Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253094 Share on other sites More sharing options...
quickstopman Posted May 14, 2007 Author Share Posted May 14, 2007 yeah some detail would be nice. im kind of a noob Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253096 Share on other sites More sharing options...
pocobueno1388 Posted May 14, 2007 Share Posted May 14, 2007 Okay, you need to start off with putting a row in your table where all their user information is kept called something like "last_active" and make it a "timestamp". Â I am assuming you have a header page that contains your layout for every page and whatever variables and what not that you need. This is where you need to update that timestamp so that it will update every time they click. Â Here is what your code should look like for your online users page, obviously you will need to change it up to match your needs. This will display all the users online that have been active in the last two minutes, you can change that as well. Â <?php $query = mysql_query("SELECT * FROM `users` WHERE `last_active` > (NOW() - INTERVAL 10 MINUTE)")or die(mysql_error()); while ($row = mysql_fetch_assoc($query)){ Â echo $row['username'].'<br>'; } ?> Â Oh, here would be your code on your header page to update their last_active field. Â mysql_query("UPDATE users SET last_active = NOW() WHERE userID='$id'"); Â Hope this helps =] Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253108 Share on other sites More sharing options...
quickstopman Posted May 14, 2007 Author Share Posted May 14, 2007 i see what your code does and i have the users online page but should i have made the timestamp a current timestamp or just plain because nothing appears on the usersonline page Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253112 Share on other sites More sharing options...
pocobueno1388 Posted May 14, 2007 Share Posted May 14, 2007 Just make it a plain timestamp...the part where it updates it will bing it to the current time, so no need to set that in the DB. Â Did you remember to put the update query on your header page? Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253120 Share on other sites More sharing options...
quickstopman Posted May 14, 2007 Author Share Posted May 14, 2007 i put it in my header page Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253121 Share on other sites More sharing options...
quickstopman Posted May 14, 2007 Author Share Posted May 14, 2007 ok i got it to work! :D thanks Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253124 Share on other sites More sharing options...
pocobueno1388 Posted May 14, 2007 Share Posted May 14, 2007 No problem ;] Quote Link to comment https://forums.phpfreaks.com/topic/51396-solved-simple-user-online-function/#findComment-253127 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.