<?
 /**
   La BD ya debe estar abierta, y las variables $user_auth y $user_id inicializadas
 **/

 // Update user-online
 $hora	  = time();
 $caducado= $hora-(300);
 $ip	  = getenv(REMOTE_ADDR);

 if ( $user_auth ) 
 {
	$uid 	= $user_id;
	$result = @mysql_query("UPDATE useronline SET hora='$hora', ip='$ip' WHERE $uid='$user_id'");
 } else {
	$uid    = 	-1;
	$result = @mysql_query("UPDATE useronline SET hora='$hora' WHERE $ip='$ip' AND $uid='-1'");
 }
 if ( @mysql_numrows($result) < 1 )
	$result	= @mysql_query("INSERT INTO useronline VALUES ('$hora','$ip','$uid')",$conexion);		

 // $result		=	@mysql_query("DELETE FROM useronline WHERE hora<'$caducado'",$conexion);	

 $result = @mysql_query("SELECT DISTINCT uid FROM useronline WHERE uid>0 AND hora>'$caducado'",$conexion);
 $ureg   = @mysql_numrows($result);
 $result = @mysql_query("SELECT DISTINCT ip FROM useronline WHERE uid<0 AND hora>'$caducado'",$conexion);
 $uinv   = @mysql_numrows($result);
 $result = @mysql_query("DELETE FORM useronline WHERE hora<'".($caducado-(2678400))."'", $conexion );
?>