Código PHP:
<?
function do_logout()
{
global $dbh,$usersdb,$livedb,$livetable;
$uid = $_SESSION['MY_UID'];
$rand = $_SESSION['MY_RAND'];
db_connect($livedb);
// Update basic info like time online, credits, etc:
list($handle,$creds,$time_online,$prefs) = user_update('','0',$uid,$rand);
// Update user stats about time online, number of logins, etc:
db_select($usersdb);
$day = date("j",time());
$month = date("n",time());
$year = date("Y",time());
$result = mysql_query("SELECT ID, day_$day FROM user_stats WHERE (uid = $uid) AND (month = $month) AND (type = 1) AND ( year = $year)") or die(mysql_error());
$row = mysql_fetch_row($result);
mysql_free_result($result);
// If there are exisiting stats, update them:
if ($row[0]){
$time_online = $time_online + $row[1];
mysql_query("UPDATE user_stats SET day_$day = '$time_online' WHERE (ID = $row[0])");
// Otherwise start a new set of stats:
}else{
mysql_query("INSERT INTO user_stats VALUES (NULL,'$uid','1','$month','$year','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')");
mysql_query("UPDATE user_stats SET day_$day = '$time_online' WHERE (uid = $uid) AND (month = $month) AND (type = 1) AND (year = $year)");
}
// Remove them from the 'Live' database, and expire any cookies:
db_select($livedb);
mysql_query("DELETE from $livetable WHERE (uid = $uid)");
mysql_query("DELETE from user_messages WHERE (private_uid = $uid AND is_copy = 0 AND has_been_read = 1) OR (creator_uid = $uid AND (private_uid = '-1' OR is_copy = 1))");
foreach ($_SESSION as $name => $value){ unset($_SESSION[$name]); }
mysql_close();
welcome("logout"); // Return them to the welcome screen.
}
?>