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
https://forums.phpfreaks.com/topic/242163-online-status/
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
https://forums.phpfreaks.com/topic/242163-online-status/#findComment-1243790
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
https://forums.phpfreaks.com/topic/242163-online-status/#findComment-1243833
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.