PHP Traffic Statistics function Implementation Code _php tutorial

Source: Internet
Author: User
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 ...

  • 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.