From fdbbe445bb654ef45aec1d5c27bd1cf864d3c0a9 Mon Sep 17 00:00:00 2001 From: yangshuimiao Date: Tue, 24 Oct 2023 09:03:37 +0800 Subject: [PATCH] update: PV Counter --- .gitignore | 1 + html/footer.php | 63 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 1d74e21..fb39811 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .vscode/ +.files/ diff --git a/html/footer.php b/html/footer.php index 8f41bfa..4f53dab 100644 --- a/html/footer.php +++ b/html/footer.php @@ -9,18 +9,14 @@ 浙ICP备18056264号-1 - -
 
-
 
-
 
- - - + + query($sql); - $mysqli->close(); + } +function pv_counter($user=''){ + global $mysqli; + $hits=0; //set default page hits 0; + $page=$_SERVER['PHP_SELF']; + + $lmtime=date("Y-m-d H:i:s"); + + $sql="select hits from pv_counter where page_name='".$page."'"; + $result=$mysqli->query($sql); + $rt=$result->fetch_all(MYSQLI_ASSOC); + + $n=count($rt); + if($n<1){ + $sql = "insert into pv_counter(page_id,Page_name,hits,lm_date,lm_ip,lm_user) + values (null, + '".$page."','1','".$lmtime."', + '".$_SERVER['REMOTE_ADDR']."','".$user."')"; + + $mysqli->query($sql); + $hits=1; + } + if($n==1){ + $hits=$rt[0]['hits']; + $hits++; + $sql="update pv_counter set hits='".$hits."',lm_date='".$lmtime."', + lm_ip='".$_SERVER['REMOTE_ADDR']."',lm_user='".$user."' where page_name='".$page."'"; + $mysqli->query($sql); + } + if($n>1){ + $display= "

There is error on pv_counter

"; + return $display; + } + $sql="select sum(hits) hits_all from pv_counter"; + $result=$mysqli->query($sql); + $hits_all=$result->fetch_all(MYSQLI_ASSOC); + $display="Page hits: ".$hits." Total: ".$hits_all[0]['hits_all']; + echo $display; + + } log_pv(); +pv_counter($user=''); +$mysqli->close(); ?> +
+ +
 
+
 
+
 
+ + + \ No newline at end of file