<?php


			
			if (isset($_COOKIE['developpez']))
			{
				echo htmlentities($_COOKIE['developpez'],ENT_QUOTES,);
			}

			
			

?>

function load_users()
{
    // Let's use AJAX also to get chatroom's users
    $.ajax({
        url: "includes/actions.php?act=getusers",
        cache: false    
    });
}
setInterval(load_messages, 500);
setInterval(load_users, 500);  

dans le fichier actions.php script

function get_users()
{

    global $tb_satker;
    // Let's get all info from "auth" table
    $sql = "SELECT * FROM $tb_satker WHERE status!=''";
    $query = mysql_query($sql);
    if(!$query){
        echo "Can not get users from database.";
    }else{
        while($row = mysql_fetch_array($query)){
            $namasatker=$row['nama_satker'];
            echo "<li><i class=\"icon-user\"></i>$namasatker</li>";
        }
    }

}


function load_users(){
    // Let's use AJAX also to get chatroom's users
    $.ajax({
        url: "includes/actions.php?act=getusers",
        cache: false,
        success: function(response) {
            $("#onlineusers").html(response);
        }
    });
}


//http://anantgarg.com/2009/05/13/gmail-facebook-style-jquery-chat/

You could have a script (AJAX) check every X minutes to see if the browser still responds, and if not, toggle offline 





CREATE TABLE `user_online` (
`session` char(100) NOT NULL default '',
`time` int(11) NOT NULL default '0'
) TYPE=MyISAM;

<?php

session_start();
$session=session_id();
$time=time();
$time_check=$time-600; //SET TIME 10 Minute

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="user_online"; // Table name

// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE session='$session'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count=="0"){

$sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')";
$result1=mysql_query($sql1);
}

else {
"$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'";
$result2=mysql_query($sql2);
}

$sql3="SELECT * FROM $tbl_name";
$result3=mysql_query($sql3);

$count_user_online=mysql_num_rows($result3);

echo "User online : $count_user_online ";

// if over 10 minute, delete session
$sql4="DELETE FROM $tbl_name WHERE time<$time_check";
$result4=mysql_query($sql4);

// Open multiple browser page for result


// Close connection

mysql_close();
?>

http://www.codeproject.com/Articles/560698/Getting-number-of-users-online-and-other-functiona


$stringIp = $_SERVER['REMOTE_ADDR'];
$intIp = ip2long($stringIp);

window.onunload

Destroy session when the User leaves the site


    <script language="javascript">
    <!--
    window.onbeforeunload = domystuff;
    function domystuff(){
       //...
    }
    //-->
    </script>
	
	
	
	    <script type="text/javascript">
    function ajaxFunction()
    {
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      xmlHttp.onreadystatechange=function()
        {
        if(xmlHttp.readyState==4)
          {
          document.myForm.time.value=xmlHttp.responseText;
          }
        }
      xmlHttp.open("GET","userlogout.php",true);
      xmlHttp.send(null);
      }
    </script>
	
	    <body onunload="ajaxFunction()">
    content
    </body>
	
	
	<script type="text/javascript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
  }
</script>

