Database-based statistics on online users and daily visits

Source: Internet
Author: User
Online user count statistics, daily traffic statistics, and monthly traffic statistics are available ..... Include (& quot; guest. php & quot;); & quot; welcome to my website for watering. if you have any questions, leave me a message. SyntaxHighlighter. all ();

Online user count statistics, daily traffic statistics, and monthly traffic statistics are available .....
$ 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.

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.