searls03 Posted July 17, 2011 Share Posted July 17, 2011 so I want to make a database that basically updates a row called login to 1 when the user is logged in and 0 when off. I am making a chat like thing and the cade will be like .........if $loggedin=0........it will show the user is offline.....if 1 it will show is online........the problem I am running into is like making it so that the user is logged off after lets say 1000 secs of inactivity.....otherwise it will say they are always logged in. is this a good way to do this? or is there a better way? I hope this makes sense. Quote Link to comment Share on other sites More sharing options...
Eiolon Posted July 17, 2011 Share Posted July 17, 2011 Can be done with jquery. Create a function that sets the idle timeout and also what events constitute as activity (key down, mouse, etc). Then create a function for what to do when idle, and what to do when active. Quote Link to comment Share on other sites More sharing options...
searls03 Posted July 17, 2011 Author Share Posted July 17, 2011 what would I do to make it so that it doesn't completely log them out....but instead it just puts them "asleep" and they just need to click to come online again? also could I get some sample jquery or whatever language..........jquery I am horrible at. Quote Link to comment Share on other sites More sharing options...
searls03 Posted July 17, 2011 Author Share Posted July 17, 2011 so I have decided to do it this way: <?php session_start(); // Must be already set $username1 = $_SESSION['username']; include_once "connect_to_mysql_1.php"; ?><?php if ($_POST['logout']) { $sql = mysql_query("UPDATE sessions SET loggedin='0' where username='$username'")or die(mysql_error()); echo "hello '$username'"; } ?> <?php if(isset($_SESSION['username'])) { $query = "SELECT username, loggedin, name FROM sessions order by loggedin desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($username, $loggedin, $name) = $row; if ($loggedin == 1){ $as .= "<p><a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$username')\">$name</a> </p>\r\n"; }else if ($loggedin == 0){ $as .= "<p><a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$username')\">$name</a> </p>\r\n"; }}} ?> only problem is I need to know how to make it so that the current session........my username lets say.....wont show to beable to chat with.....so you cant chat with yourself haha. make sense? Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted July 17, 2011 Share Posted July 17, 2011 If it's a chat thing then you could use a cronjob that runs every 10 or so seconds which goes through all logged in users setting them to brb or away based on the time difference from now and there last action (stored in a db). That is how the thing I'm making works, or will. Quote Link to comment Share on other sites More sharing options...
searls03 Posted July 17, 2011 Author Share Posted July 17, 2011 Ok so could u give me a sample from job? My webhist has em but i don't know how to use them. Quote Link to comment 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.