Home > Backend Development > PHP Tutorial > Online time. Roughly calculate the online time. Bug: IP is the same.

Online time. Roughly calculate the online time. Bug: IP is the same.

WBOY
Release: 2016-07-29 08:35:40
Original
963 people have browsed it

/*
CREATE TABLE `db_online` (
`ip` char(20) default NULL,
`time` char(20) NOT NULL default '',
`name` char(200) NOT NULL default 'Guest'
) TYPE=MyISAM
*/
//Rough calculation of online time, bug: If the IP is the same (LAN -> External network), only one person is recorded. But the chance is very small
session_start();
//Timeout time
$out_time=300;//60*5
$uesr_name=$_SESSION['uesr_name'];
$now=time();
$
$ip =$_SERVER["REMOTE_ADDR"];
mysql_connect("localhost","root","");
mysql_select_db("database");
//Delete outdated users.
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','visitor') ");
}
?>

The above introduces the online time and roughly calculates the online time. The bug: IP is the same, including the online time. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template