php流量統(tǒng)計(jì)功能的實(shí)現(xiàn)代碼
更新時(shí)間:2012年09月29日 22:09:38 作者:
用php實(shí)現(xiàn)的流量統(tǒng)計(jì)功能代碼,本代碼僅供學(xué)習(xí)交流,其中必有不妥之處。請見諒
流量統(tǒng)計(jì)功能
顯示效果:
總訪問量:399
今日流量:14
昨日流量:16
本代碼僅供學(xué)習(xí)交流,其中必有不妥之處。請見諒!
--
-- 表的結(jié)構(gòu) `mycounter`
--
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 ;
函數(shù)過程如下:
<?PHP
public function ShowMyCounter(){
//定義變量
$IsGone = FALSE;
//讀取數(shù)據(jù)
$querysql = "SELECT * FROM `mycounter` WHERE id = Ƈ' ";
$queryset = mysql_query($querysql);
$row = mysql_fetch_array($queryset);
//獲得時(shí)間量
$DateNow = date('Y-m-d');
$RecordDate = $row['RecordDate'];
$DateNow_explode = explode("-",$DateNow);
$RecordDate_explode = explode("-",$RecordDate);
//判斷是否已過去一天
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;
//根據(jù)IsGone進(jìn)行相應(yīng)操作
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);
}
//再次獲取數(shù)據(jù)
$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 "總訪問量:".$Counter;
echo "
";
echo "今日流量:".$CounterToday;
echo "
";
echo "昨日流量:".$CounterLastDay;
}else{//如果數(shù)據(jù)庫為空時(shí),相應(yīng)的操作
}
}
?>
當(dāng)然,需要在文件第一行開始寫出如下代碼:
<?PHP
session_start();
if( !isset($_COOKIE["user"]) ){
setcookie("user","newGuest",time()+3600);
}else {
setcookie("user","oldGuest");
}
?>
顯示效果:
總訪問量:399
今日流量:14
昨日流量:16
本代碼僅供學(xué)習(xí)交流,其中必有不妥之處。請見諒!
--
-- 表的結(jié)構(gòu) `mycounter`
--
復(fù)制代碼 代碼如下:
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 ;
函數(shù)過程如下:
復(fù)制代碼 代碼如下:
<?PHP
public function ShowMyCounter(){
//定義變量
$IsGone = FALSE;
//讀取數(shù)據(jù)
$querysql = "SELECT * FROM `mycounter` WHERE id = Ƈ' ";
$queryset = mysql_query($querysql);
$row = mysql_fetch_array($queryset);
//獲得時(shí)間量
$DateNow = date('Y-m-d');
$RecordDate = $row['RecordDate'];
$DateNow_explode = explode("-",$DateNow);
$RecordDate_explode = explode("-",$RecordDate);
//判斷是否已過去一天
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;
//根據(jù)IsGone進(jìn)行相應(yīng)操作
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);
}
//再次獲取數(shù)據(jù)
$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 "總訪問量:".$Counter;
echo "
";
echo "今日流量:".$CounterToday;
echo "
";
echo "昨日流量:".$CounterLastDay;
}else{//如果數(shù)據(jù)庫為空時(shí),相應(yīng)的操作
}
}
?>
當(dāng)然,需要在文件第一行開始寫出如下代碼:
復(fù)制代碼 代碼如下:
<?PHP
session_start();
if( !isset($_COOKIE["user"]) ){
setcookie("user","newGuest",time()+3600);
}else {
setcookie("user","oldGuest");
}
?>
您可能感興趣的文章:
- php實(shí)現(xiàn)用戶在線時(shí)間統(tǒng)計(jì)詳解
- php下用cookie統(tǒng)計(jì)用戶訪問網(wǎng)頁次數(shù)的代碼
- php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法
- php利用cookie實(shí)現(xiàn)訪問次數(shù)統(tǒng)計(jì)代碼
- php使用Session和文件統(tǒng)計(jì)在線人數(shù)
- 也談php網(wǎng)站在線人數(shù)統(tǒng)計(jì)
- PHP實(shí)現(xiàn)統(tǒng)計(jì)在線人數(shù)功能示例
- php簡單統(tǒng)計(jì)在線人數(shù)的方法
- PHP實(shí)現(xiàn)簡單網(wǎng)站訪客統(tǒng)計(jì)的方法實(shí)例
相關(guān)文章
PHP數(shù)組函數(shù)array_multisort()用法實(shí)例分析
這篇文章主要介紹了PHP數(shù)組函數(shù)array_multisort()用法,結(jié)合實(shí)例形式詳細(xì)分析了array_multisort函數(shù)的功能,定義及進(jìn)行數(shù)組排序過程中的使用技巧,需要的朋友可以參考下2016-04-04
PHP消息隊(duì)列實(shí)現(xiàn)及應(yīng)用詳解【隊(duì)列處理訂單系統(tǒng)和配送系統(tǒng)】
這篇文章主要介紹了PHP消息隊(duì)列實(shí)現(xiàn)及應(yīng)用,結(jié)合實(shí)例形式詳細(xì)分析了php消息隊(duì)列的概念、原理及隊(duì)列處理訂單系統(tǒng)和配送系統(tǒng)案例,需要的朋友可以參考下2019-05-05
php獲取$_POST同名參數(shù)數(shù)組的實(shí)現(xiàn)介紹
本篇文章是對php獲取$_POST同名參數(shù)數(shù)組的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

