Home  >  Article  >  Backend Development  >  Implementation code of php traffic statistics function_PHP tutorial

Implementation code of php traffic statistics function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:271279browse

Traffic statistics function
Display effect:
Total visits: 399
Today’s traffic: 14
Yesterday’s traffic: 16
This code is only for learning and communication, and there must be something wrong in it. Please forgive me!
--
-- The structure of the table `mycounter`
--

Copy code 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:
Copy code The code is as follows:

public function ShowMyCounter(){
//Define variables
$IsGone = FALSE;
//Read 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);
//Determine whether it has passed day
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 corresponding 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 = Ƈ' ";
mysql_query($upd_sql);
}
//Get 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 traffic: ".$CounterLastDay;
}else{//If the database is empty, the corresponding operation
}
}
?>

Of course, you need to write the following code starting from the first line of the file:
Copy code The code is as follows:

session_start();
if( !isset($_COOKIE["user"]) ){
setcookie("user ","newGuest",time()+3600);
}else {
setcookie("user","oldGuest");
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326117.htmlTechArticle Traffic statistics function display effect: Total visits: 399 Today’s traffic: 14 Yesterday’s traffic: 16 This code is for learning only There must be something wrong with communication. Please forgive me! -- -- Table structure `m...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn