irkevin Posted September 28, 2007 Share Posted September 28, 2007 Ok i read all of the post about showing online users but im stuck I tried to make a script which shows which one is logged in.. I have a table like this uname | ip | time | guest and here is the code im using to show the number of members and guest .. $uname = $_SESSION['user_name']; if (!$uname) { $guest = 1; } else { $guest = 0; } $ip = $_SERVER['REMOTE_ADDR']; $time = time(); $query = "SELECT * FROM user_online WHERE ip = '$ip'"; $result = mysql_query($query); if (mysql_num_rows($result) == 1) { $query2 = "UPDATE user_online SET uname='$uname',time='$time',guest='$guest' WHERE ip = '$ip'"; $result2 = mysql_query($query2); } else { $query2 = "INSERT INTO user_online (uname,ip,time,guest)VALUES('$uname', '$ip', '$time','$guest')"; $result2 = mysql_query($query2); } $time3 = time() - 300; $query3 = "DELETE FROM user_online WHERE time < $time3"; $result3 = mysql_query($query3); $query4 = "SELECT * FROM user_online WHERE guest = '1'"; $result4 = mysql_query($query4); $guestonline = mysql_num_rows($result4); $query5 = "SELECT * FROM user_online WHERE guest = '0'"; $result5 = mysql_query($query5); $memonline = mysql_num_rows($result5); $totalonline = $guestonline + $memonline; echo "Guests: $guestonline<br /> Members: $memonline<br /> Total: $totalonline<br /><br />"; this is the code im using to show the names of logged users.. $sql = "SELECT * FROM user_online WHERE guest = '0'"; $result = mysql_query($sql,$conn); while($sql = mysql_fetch_object($result)){ $_uname = $sql -> uname; echo $_uname; echo "<br>"; } whats happening is, when a person logs out, the name remains there. is there a way to remove the name once the user has logged out? Would be nice if someone could help me with it and show me the right path to it. Maybe i took the wrong way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/ Share on other sites More sharing options...
irkevin Posted September 28, 2007 Author Share Posted September 28, 2007 basically i want it to show the username just after the user has logged in, and remove it right after the user logs out ... is it a problem with the time i used in my code? Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-356995 Share on other sites More sharing options...
hemlata Posted September 28, 2007 Share Posted September 28, 2007 Hello, Basically, some how you need to reload the page once user gets logout as without reloading the page the new record information will not be displayed.. Regards, Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357079 Share on other sites More sharing options...
irkevin Posted September 28, 2007 Author Share Posted September 28, 2007 how to do that? with meta equiv?? i almost lost with it Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357445 Share on other sites More sharing options...
irkevin Posted September 28, 2007 Author Share Posted September 28, 2007 the code for showing the usernames who are online is in another page name online_now.php.. You mean i have to reload that page? what i want to have is, when the user logs out, it removes his name from the tables. see what i mean? Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357447 Share on other sites More sharing options...
SharkBait Posted September 28, 2007 Share Posted September 28, 2007 Usually you cannot tell when someone logs out. They might close their browser, or click the 'logout' link or their computer might crash. Most system I see show a 'People Logged in the past 5 mins' and then query to see when the last activity was of the person on the site. If there was no activity for more than 5 minutes the system would assume they 'logged' out Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357461 Share on other sites More sharing options...
irkevin Posted September 28, 2007 Author Share Posted September 28, 2007 ok but what about the code i posted.. can u some errors in it? Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357478 Share on other sites More sharing options...
irkevin Posted September 29, 2007 Author Share Posted September 29, 2007 bump no one?? Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-357623 Share on other sites More sharing options...
irkevin Posted September 30, 2007 Author Share Posted September 30, 2007 wow really no one.. ok then :'( Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358249 Share on other sites More sharing options...
irkevin Posted September 30, 2007 Author Share Posted September 30, 2007 bump No one? :S delete this post then plz Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358720 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 what i want to have is, when the user logs out, it removes his name from the tables. see what i mean? impossible if your talking like my name will be deleted in your page without refreshing! Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358722 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 if you can see in this forum when you log out your name is deleted in your page but not in our page unless we refresh the page but if you want it that way you can try a frame where in the top page is refreshing every 10 seconds etc... Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358723 Share on other sites More sharing options...
NottaGuru Posted October 1, 2007 Share Posted October 1, 2007 I made something similiar to this in a project I was doing. I probably did it the hard way, but here goes (Note: This is only the basics...). I have a table... User, Date, Time, Status. When a user logs in, coding is used to update the table (or add a new row) with the date and time. Status is set to 'On Line'. When a user goes to a page (Home, Contact, About, etc), coding at the top of the page updates the table with the new date and time, or updates the table by setting the status to 'Off Line' and then adds a new row with 'On Line'. There is also code to check the table for all 'On Line' status's. It uses a pain in the butt formula to check all the dates/times to see if any are older than say 10 minutes. If the date/time is older than 10 minutes, then the user has not moved for at least that long. This date/time check is for ALL 'On Line', not just the current user. If it finds an 'On Line' row older than 10 minutes, it changes the status to 'Off Line'. If that user was really on-line, then when they move, a new line will be added for them and they will be 'On Line' again. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358765 Share on other sites More sharing options...
irkevin Posted October 1, 2007 Author Share Posted October 1, 2007 if you can see in this forum when you log out your name is deleted in your page but not in our page unless we refresh the page but if you want it that way you can try a frame where in the top page is refreshing every 10 seconds etc... obviously it won't go on ur page.. but can you plz tell me if there is some kind of error in my code? im new to this stuff but still trying my best to get working.. I somehow manage to get the name to appear on a page.. somehow, refreshing it every 50 seconds or whatsoever would be better i presume.. the ones logged in would be able to know which one is still online Quote Link to comment https://forums.phpfreaks.com/topic/70994-names-of-online-users/#findComment-358838 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.