Statistics on online numbers, daily visits, etc. based on database

Source: Internet
Author: User
Tags count datetime connect unique id
can achieve online statistics, daily traffic statistics, monthly traffic statistics ....

?
$sql = "CREATE TABLE guestinfo (id integer DEFAULT ' 0 ' not NULL auto_increment,
IPAddress varchar (20),
Host varchar (20),
Cometime datetime,
Refreshtime datetime,
Leavetime datetime,
PRIMARY KEY (ID),
UNIQUE ID (ID),
Index Guestinfo (ID)
)";
mysql_query ($sql, $connect);
?>

?
$duration = 300;
$sql = "SELECT * from Guestinfo where (Leavetime are null or leavetime= ') and (Unix_timestamp (now ())-unix_timestamp (REFR eshtime)) > $duration ";
$result = @mysql_query ($sql);
while ($row = @mysql_fetch_array ($result))
{
$id = $row [' id '];
$sql = "Update guestinfo set Leavetime=now () where id= ' $id '";
mysql_query ($sql);

}
$sql = "SELECT * from Guestinfo where ipaddress= ' $REMOTE _addr ' and (Leavetime is null or leavetime= ')";
$result = @mysql_query ($sql);
if ($row = @mysql_fetch_array ($result))
{
$id = $row [' id '];
$sql = "Update guestinfo set Refreshtime=now () where id= ' $id '";
mysql_query ($sql);
}
Else
{
$sql = "INSERT into Guestinfo (ipaddress,host,cometime,refreshtime)
VALUES (' $REMOTE _addr ', ' $REMOTE _host ', now (), now ()) ";
mysql_query ($sql);
}
$date = Mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
$sql = "SELECT count (*) from Guestinfo where Unix_timestamp (refreshtime) > $date";
$result = mysql_query ($sql);
if ($result)
{
$row = Mysql_fetch_array ($result);
$todayaccess = $row ["Count (*)]";
}
else $todayaccess = 0;

$sql = "SELECT count (*) from guestinfo where leavetime is null or leavetime= '";
$result = mysql_query ($sql);
if ($result)
{
$row = Mysql_fetch_array ($result);
$nowonline = $row ["Count (*)]";
}
else $nowonline = 0;
Mysql_close ($connect);
?>

Include ("guest.php");
<meta http-equiv= "Refresh" CONTENT=&LT;? Echo $duration?>; url=<? echo $PHP _self?> ">
Welcome to my website to irrigation, what is the problem, give me a message.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.