chocopi Posted May 15, 2007 Share Posted May 15, 2007 Ok i would like a script for users online. i am unfamilar with timestamps and such so any help would be greatly apprciated. ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51455-solved-users-online-from-scratch/ Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 do a search on this -- for posts made by me -- there is one of these... i made one that is on these forums. Quote Link to comment https://forums.phpfreaks.com/topic/51455-solved-users-online-from-scratch/#findComment-253450 Share on other sites More sharing options...
chocopi Posted May 15, 2007 Author Share Posted May 15, 2007 is this the one you were talking about ? <?php if ($_SESSION['admin']['intime'] != '') { if ($_SESSION['admin']['intime'] < time() - 1800) { session_unset('admin'); $over = "1800"; echo "ERROR: you have been idle for more than 1800 seconds. Please login again"; }} $_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; switch ($_action) { default: if (!isset($_SESSION['admin'])) { if ($over != "1800") { echo 'Authorization Required. Please log in.' } // login form html here } else { include of the page you wish to show } break; case login: if ($_REQUEST['act'] != "login") { if (isset($_SESSION['admin']) ) { // update session } if ($_SESSION['admin']['username'] != '') { // include of the page you want to view } else { if ($over != "1800") { echo "authorization required"; } // login form include } } else { // the query to the database, (use LIKE BINARY for case sensitivity) // also the cookie/session creation would go here if ($login == "true") { // show the actual page you want them to view } else { // show the login form } } break; } ?> Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/51455-solved-users-online-from-scratch/#findComment-253511 Share on other sites More sharing options...
radar Posted May 16, 2007 Share Posted May 16, 2007 No that is a login script -- this is from a LONG LONG time ago -- let me see if i can find it on here for you. -- edit: after doing some searching I found my code... <?php $time = time() - 60 * 15; $mems = "SELECT * FROM members WHERE last_activity <= $time"; $mems = mysql_num_rows(mysql_query($mems), 0); $guest = "SELECT * FROM online_guests"; $guest = mysql_num_rows(mysql_query($guest), 0); $tot = "SELECT * FROM members"; $tot = mysql_num_rows(mysql_query($tot), 0); echo $mems." members online"; echo $guest." guests online"; echo $tot." total members"; ?> That code will generate a count of each who are online... please note that I am no longer using this code, but it did work @ the time of conception -- you will need to modify it a little to fit your application. <?php $time = time() - 60 * 15; $mems = "SELECT * FROM members WHERE last_activity <= $time"; $mems = mysql_query($mems); $cnt = mysql_num_rows($mems); for ($i = 0; $i < $cnt && $rows = mysql_fetch_assoc($mems); $i++) { echo $rows['username'].', '; } ?> This here will give you a list of usernames who are currently online (within 15 minutes)... This has not been tested, but by the looks of things should work without any problems.... <?php $time = time() - 15 * 60 $mem = "SELECT inout FROM users WHERE username = '$user_name'"; $mem = mysql_query($mem); $mem = mysql_result($mem, 0); if ($mem == "in") { echo '<img src="in.gif">'; } else { echo '<img src="out.gif">'; } ?> This here is to have a online/offline image next to a users name, in a forum setting this would need to be dramatically changed as this will only do a single user instead of all the users who have posted in a forum or whatever... I hope that these 3 code samples help you in figuring out what you want and need to do, to get something working for your site. And as I say to everyone, if you need any help I am only a PM away. Quote Link to comment https://forums.phpfreaks.com/topic/51455-solved-users-online-from-scratch/#findComment-254153 Share on other sites More sharing options...
john010117 Posted May 16, 2007 Share Posted May 16, 2007 However, if you want somebody to completely make the code for you, please post your request in the freelancers area. Quote Link to comment https://forums.phpfreaks.com/topic/51455-solved-users-online-from-scratch/#findComment-254173 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.