<div id='footer'>
<p>&nbsp;</p>
<hr style='text-align: center;width: 980px;border-width: 0;background-color: gray;height: 1px;' id='foot_hr'  >

<div style='text-align: center'>Powered by Simon Young <span style="font-family: Arial; font-size: x-small; "> &copy; </span>2019-<?=date('Y')?>
&nbsp;All Right Reserved <a href="mailto:simon.youngest@gmail.com" title='simon.youngest@gmail.com'>E-mail</a>.
</div>
<div style='text-align: center'>
<span style="color: grey; font-size: x-small; ">
    <a href="https://beian.miit.gov.cn" target="_blank">浙ICP备18056264号-1</a>
</span>

<span style='color:grey;font-size:small;'>
<?php
ini_set("display_errors", "1");
$mysqli = new mysqli('localhost','root','nancysimon','myquant');
function log_pv(){
    #echo "start log";
    global $mysqli;
    $vpage  = addslashes($_SERVER['PHP_SELF']);
    $ua     = addslashes($_SERVER['HTTP_USER_AGENT']);
    $ip     = $_SERVER['REMOTE_ADDR'];
    $qs     = addslashes($_SERVER['QUERY_STRING']);
    $vtime  = date("Y-m-d H:i:s");

    $sql="insert into pv_log(vpage,querystring,remoteip,ua,vtime)
                  values ('".$vpage."','".$qs."','".$ip."', '".$ua."','".$vtime."')";

    $mysqli->query($sql);
   
}
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= "<p align='center'>There is error on pv_counter </p>";
                  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();
?>
</span>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
</div>
</body>
</html>