<?php

//在线
$username = !empty($session[0]) ? $session[0] : user_ip();
$userface = !empty($userface) ? $userface : '';
//判断表是不是已存在
if (@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'`', $db)) {
  @mysql_query('REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'` (`username`,`memberye`,`userface`,`utime`,`position`,`title`) VALUES ("'.$username.'","'.POWER.'","'.addslashes($userface).'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"'.addslashes(basename($_SERVER['REQUEST_URI'])).'","'.$title.'")', $db);


  $web['onlinetimed'] = is_numeric($web['onlinetimed']) ? $web['onlinetimed'] : 30;
  @mysql_query('DELETE FROM `'.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'` WHERE utime<DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.(floatval($web['time_pos']) * 60 - $web['onlinetimed']).' MINUTE)');

} else {
  //DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  $table_born = 'CREATE TABLE '.$sql['pref'].''.$sql['data']['承载在线统计的表名'].' (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `username` varchar(64) NOT NULL DEFAULT \'\',
  `memberye` int(2) NOT NULL DEFAULT \'0\',
  `userface` text NOT NULL,
  `utime` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\',
  `position` varchar(255) NOT NULL DEFAULT \'\',
  `title` varchar(255) NOT NULL DEFAULT \'\',
  PRIMARY KEY (id),
  UNIQUE username (username),
  KEY memberye (memberye)
) '.(@mysql_get_server_info() > '4.1' ? ' ENGINE=MyISAM DEFAULT CHARSET='.$sql['char'].'' : ' TYPE=MYISAM').';
';

  $table_into = 'INSERT INTO `'.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'` (`memberye`,`username`,`userface`,`utime`,`position`,`title`) VALUES ("'.POWER.'","'.$username.'","'.addslashes($userface).'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"'.addslashes(basename($_SERVER['REQUEST_URI'])).'","'.$title.'")';
  if (@mysql_query($table_born)) { //创建表并判断
    if (!@mysql_query($table_into, $db)) {
      //echo mysql_errno().':'.mysql_error();
    }
  } else {
    //echo mysql_errno().':'.mysql_error();
  }

}

?>