Php traffic statistics function implementation code. The traffic statistics function shows the effect: total traffic: 399 today's traffic: 14 yesterday's traffic: 16 this code is only for learning and communication, which must be inappropriate. Sorry! ---- Table structure'm traffic statistics function
Display effect:
Total traffic: 399
Today's traffic: 14
Yesterday's traffic: 16
This code is only for learning and communication, and there must be something wrong with it. Sorry!
--
-- Table structure 'mycounter'
--
The code is as follows:
Create table 'mycounter '(
'Id' int (11) not null auto_increment,
'Counter' int (11) not null,
'Counterlastday' int (10) default NULL,
'Countertoday' int (10) default NULL,
'Recorddate' date not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 2;
The function process is as follows:
The code is as follows:
Public function ShowMyCounter (){
// Define variables
$ IsGone = FALSE;
// Read data
$ Querysql = "SELECT * FROM 'mycounter 'WHERE id = comment '";
$ Queryset = mysql_query ($ querysql );
$ Row = mysql_fetch_array ($ queryset );
// Obtain the time amount
$ DateNow = date ('Y-m-D ');
$ RecordDate = $ row ['recorddate'];
$ DateNow_explode = explode ("-", $ DateNow );
$ RecordDate_explode = explode ("-", $ RecordDate );
// Determine whether the previous day has passed
If ($ DateNow_explode [0]> $ RecordDate_explode [0]) $ IsGone = TRUE;
Else if ($ DateNow_explode [0] ==$ RecordDate_explode [0]) {
If ($ DateNow_explode [1]> $ RecordDate_explode [1]) $ IsGone = TRUE;
Else if ($ DateNow_explode [1] ==$ RecordDate_explode [1]) {
If ($ DateNow_explode [2]> $ RecordDate_explode [2]) $ IsGone = TRUE;
} Else BREAK;
} Else BREAK;
// Perform operations based on IsGone
IF ($ IsGone ){
$ RecordDate = $ DateNow;
$ CounterToday = 0;
$ CounterLastDay = $ row ['countertoday'];
$ Upd_ SQL = "update mycounter set RecordDate = '$ recorddate', CounterToday =' $ countertoday', CounterLastDay = '$ CounterLastDay' WHERE id = comment '";
Mysql_query ($ upd_ SQL );
}
// Obtain data again
$ Querysql = "SELECT * FROM 'mycounter 'WHERE id = comment '";
$ Queryset = mysql_query ($ querysql );
$ Counter = $ row ['counter'];
$ CounterToday = $ row ['countertoday'];
$ CounterLastDay = $ row ['counterlastday'];
If ($ row = mysql_fetch_array ($ queryset )){
If ($ _ COOKIE ["user"]! = "OldGuest "){
$ Counter = ++ $ row ['counter'];
$ CounterToday = + $ row ['countertoday'];
$ Upd_ SQL = "update mycounter set counter = '$ counter', CounterToday =' $ CounterToday 'WHERE id = comment '";
$ Myquery = mysql_query ($ upd_ SQL );
}
Echo "total access volume:". $ Counter;
Echo"
";
Echo "today's traffic:". $ CounterToday;
Echo"
";
Echo "yesterday's traffic:". $ CounterLastDay;
} Else {// The corresponding operation if the database is empty
}
}
?>
Of course, the following code must be written at the first line of the file:
The code is as follows:
Session_start ();
If (! Isset ($ _ COOKIE ["user"]) {
Setcookie ("user", "newGuest", time () + 3600 );
} Else {
Setcookie ("user", "oldGuest ");
}
?>
Display effect: total traffic: 399 today's traffic: 14 yesterday's traffic: 16 this code is only for learning and communication, which must be inappropriate. Sorry! -- Table structure'm...