Codice PHP:
function show_online()
{
$timeout = 600;
$sqldel = "DELETE FROM dt_it_online WHERE UNIX_TIMESTAMP(NOW()) > timeout";
$dsqldel = mysql_query($sqldel, $this->cdb);
$sqlonl = "SELECT * FROM dt_it_online WHERE ip = '".$_SERVER["REMOTE_ADDR"]."'";
$dsqlonl = mysql_query($sqlonl, $this->cdb);
$nsqlonl = mysql_num_rows($dsqlonl);
if($nsqlonl > 0)
{
$sqlmesess = "UPDATE dt_it_online SET timeout = UNIX_TIMESTAMP(NOW())+".$timeout." WHERE ip = '".$_SERVER["REMOTE_ADDR"]."'";
}
else
{
$sqlmesess = "INSERT INTO dt_it_online (ip,stato,ora,timeout) VALUES ('".$_SERVER["REMOTE_ADDR"]."','0',UNIX_TIMESTAMP(NOW()),UNIX_TIMESTAMP(NOW())+".$timeout.")";
}
$dsqlmesess = mysql_query($sqlmesess, $this->cdb);
$sqlconl = "SELECT COUNT(*) AS online FROM dt_it_online";
$dsqlconl = mysql_query($sqlconl, $this->cdb);
$onl = mysql_fetch_array($dsqlconl);
return $onl["online"];
}