Database-based statistics on online users and daily visits
Source: Internet
Author: User
Online user count statistics, daily traffic statistics, and monthly traffic statistics can be achieved .....? $ SqlCREATETABLEguestinfo (region, ipaddressvarchar (20), hostvarchar (20), cometimedatetime, refreshtimedatetime, leavetimedatetime, and PRIMARYK can be used to calculate the number of online users, daily visits, and monthly visits .....
$ 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 is null or leavetime ='') and (UNIX_TIMESTAMP (NOW ()-UNIX_TIMESTAMP (refreshtime)> $ 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 ");
; Url = ">
Welcome to my website for watering. if you have any questions, leave a message for me.
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.