微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php流量统计功能的实现代码

流量统计功能
显示效果
总访问量:399
今日流量:14
昨日流量:16
代码仅供学习交流,其中必有不妥之处。请见谅!
--
-- 表的结构 mycounter
--
<div class="codetitle"><a style="CURSOR: pointer" data="179" class="copybut" id="copybut179" onclick="doCopy('code179')"> 代码如下:

<div class="codebody" id="code179">
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 ;

函数过程如下:
<div class="codetitle"><a style="CURSOR: pointer" data="91893" class="copybut" id="copybut91893" onclick="doCopy('code91893')"> 代码如下:
<div class="codebody" id="code91893">
<?PHP
public function ShowMyCounter(){
//定义变量
$IsGone = FALSE;
//读取数据
$querysql = "SELECT FROM mycounter WHERE id = Ƈ' ";
$queryset = MysqL_query($querysql);
$row = MysqL_fetch_array($queryset);
//获得时间量
$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;
//根据IsGone进行相应操作
IF($IsGone) {
$RecordDate = $DateNow;
$CounterToday = 0;
$CounterLastDay = $row['CounterToday'];
$upd_sql = "update mycounter set RecordDate = '$RecordDate',CounterToday = '$CounterToday',CounterLastDay = '$CounterLastDay' WHERE id = Ƈ' ";
MysqLquery($updsql);
}
//再次获取数据
$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 = MysqLquery($updsql);
}
echo "总访问量:".$Counter;
echo "
";
echo "今日流量:".$CounterToday;
echo "
";
echo "昨日流量:".$CounterLastDay;
}else{//如果数据库为空时,相应的操作
}
}
?>

当然,需要在文件第一行开始写出如下代码
<div class="codetitle"><a style="CURSOR: pointer" data="69867" class="copybut" id="copybut69867" onclick="doCopy('code69867')"> 代码如下:
<div class="codebody" id="code69867">
<?PHP
session_start();
if( !isset($_COOKIE["user"]) ){
setcookie("user","newGuest",time()+3600);
}else {
setcookie("user","oldGuest");
}
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐