Heim  >  Artikel  >  Backend-Entwicklung  >  粗略计算在线时间,bug:ip相同_PHP教程

粗略计算在线时间,bug:ip相同_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:58:59923Durchsuche

/*

CREATE TABLE `db_online` (
  `ip` char(20) default NULL,
  `time` char(20) NOT NULL default '',
  `name` char(200) NOT NULL default '游客'
) TYPE=MyISAM

*/

//粗略计算在线时间,bug:ip相同(局域网->外部网)者,只记录一人。不过几率很少

session_start();
//超时时间
$out_time=300;//60*5

$uesr_name=$_SESSION['uesr_name'];

$now=time();
$online="db_online";
$ip=$_SERVER["REMOTE_ADDR"];

mysql_connect("localhost","root","");
mysql_select_db("数据库");
//删除过时用户.
mysql_query("delete from `$online` where  ($now-`time`)>$out_time or `name`='$uesr_name'  or `ip`='$ip' ");

if($uesr_name){
    mysql_query("  INSERT INTO `$online` (`ip`, `time`, `name`) VALUES ('$ip','$now','$uesr_name')  ");
}else{
    mysql_query("  INSERT INTO `$online` (`ip`, `time`, `name`) VALUES ('$ip','$now','游客')  ");
}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/317465.htmlTechArticle?PHP /* CREATETABLE`db_online`( `ip`char(20)defaultNULL, `time`char(20)NOTNULLdefault'', `name`char(200)NOTNULLdefault'游客' )TYPE=MyISAM */ //粗略计算在线时间,bug:ip相同(...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn