Ti lascio qui il method che ho creato per il phpnix 4. Funziona alla grande ed è similare a quello del phpBB
Codice PHP:// METHOD: this method add or delete users in ONLINE_TABLE [I call this method in header()]
private function online_function()
{
$sql = "SELECT * FROM " . ONLINE_TABLE;
$result = $this->db->sql_query($sql);
// Now I delete all users with their time > gb_config['onlin_seconds']
$time = time();
if( $this->get_db_stat('onlinecount') > 0 )
{
while( $row = $this->db->sql_fetch_row($result) )
{
$sql = "DELETE FROM " . ONLINE_TABLE . " WHERE online_time < " . (time()-$this->gb_config['online_seconds']);
$result = $this->db->sql_query($sql);
}
}
$sql = "SELECT * FROM " . ONLINE_TABLE;
$result = $this->db->sql_query($sql);
// Now I add a user
$time = time();
if( $this->get_db_stat('onlinecount') == 0 )
{
$sql = "INSERT INTO " . ONLINE_TABLE . " (online_ip, online_time) VALUES ('$this->user_ip', '$time')";
$result = $this->db->sql_query($sql);
}
else
{
while( $row = $this->db->sql_fetch_row($result) )
{
if( $this->user_ip == $row['online_ip'] )
{
$sql = "UPDATE " . ONLINE_TABLE . " SET online_time = '$time' WHERE online_ip='$this->user_ip'";
$result = $this->db->sql_query($sql);
return;
}
}
$sql = "INSERT INTO " . ONLINE_TABLE . " (online_ip, online_time) VALUES ('$this->user_ip', '$time')";
$result = $this->db->sql_query($sql);
}
} // End method online_function

Rispondi quotando