Jump to content

online status


searls03

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.