Traffic statistics function
Display effect:
Total Visits: 399
Today's traffic: 14
Yesterday's flow: 16
This code is for learning communication only, there must be inappropriate. Please forgive me!
--
--The structure of the table ' MyCounter '
--
Copy CodeThe code is as follows:
CREATE TABLE ' MyCounter ' (
' id ' int (one) not NULL auto_increment,
' Counter ' int (one) is not NULL,
' Counterlastday ' int (ten) is default NULL,
' Countertoday ' int (ten) is default NULL,
' Recorddate ' date not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT CHARSET=GBK auto_increment=2;
The Function procedure is as follows:
Copy CodeThe code is as follows:
Public Function Showmycounter () {
Defining variables
$IsGone = FALSE;
Reading data
$querysql = "SELECT * from ' mycounter ' WHERE ID =ƈ '";
$queryset = mysql_query ($querysql);
$row = Mysql_fetch_array ($queryset);
Get the amount of time
$DateNow = Date (' y-m-d ');
$RecordDate = $row [' recorddate '];
$DateNow _explode = Explode ("-", $DateNow);
$RecordDate _explode = Explode ("-", $RecordDate);
Judging whether the 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;
According to the Isgone to do the corresponding operation
IF ($IsGone) {
$RecordDate = $DateNow;
$CounterToday = 0;
$CounterLastDay = $row [' Countertoday '];
$UPD _sql = "Update mycounter set recorddate = ' $RecordDate ', countertoday = ' $CounterToday ', counterlastday = ' $CounterLast Day ' WHERE ID =ƈ ' ";
mysql_query ($upd _sql);
}
Get the data again
$querysql = "SELECT * from ' mycounter ' WHERE ID =ƈ '";
$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 =ƈ '";
$myquery = mysql_query ($upd _sql);
}
echo "Total visits:". $Counter;
echo "
";
echo "Today's traffic:". $CounterToday;
echo "
";
echo "Yesterday's Flow:". $CounterLastDay;
}else{//If the database is empty, the corresponding action
}
}
?>
Of course, you need to start writing the following code on the first line of the file:
Copy CodeThe code is as follows:
Session_Start ();
if (!isset ($_cookie["user")) {
Setcookie ("User", "Newguest", Time () +3600);
}else {
Setcookie ("User", "oldguest");
}
?>
http://www.bkjia.com/PHPjc/326117.html www.bkjia.com true http://www.bkjia.com/PHPjc/326117.html techarticle Traffic Statistics function display effect: Total visits: 399 Today traffic: 14 Yesterday traffic: 16 This code is only for learning communication, there must be something wrong. Please forgive me! Structure of the----table ' m ...