php+mysql实现统计网站访问量(一)

环境:centos6.9;mysql5.1;php7.2

1.创建一个存储数据的表

create table wp_jc_count(
    id int not null auto_increment primary key,
    ip varchar(20) not null,
    times int default 0
    );

2.创建一个php脚本

";
        //echo $_SERVER['REMOTE_ADDR']."
"; }else{ echo "失败\n"; die(mysqli_connect_error()); } //设置数据库编码方式 mysqli_set_charset($conn,"utf8") or die(mysqli_connect_error()); //记录访客的ip地址 $address=$visitor->getIp(); //查询当前访客来访的次数的sql语句 $sql="select times from wp_jc_count where ip='$address'"; //查询结果存到$result变量 $result=mysqli_query($conn,$sql) or die(mysqli_connect_error()); if(!$row=$result->fetch_row()){ $sql="insert into wp_jc_count(ip, times) values('$address','1')"; }else{ $times=$row['0']+1; $sql="update wp_jc_count set times='$times' where ip ='$address'"; } $result=mysqli_query($conn,$sql) or die(mysqli_connect_error()); //获取总的访问人数即数据表中所有ip的数量 $sql="select count(ip) from wp_jc_count"; $result=mysqli_query($conn,$sql) or die(mysqli_connect_error()); if($row=$result->fetch_row()){ $num=$row[0]; } echo "您是第".$num."位访客"; mysqli_close($conn); ?>

3.将上述代码贴到footer.php中要输出信息的位置即可

当前功能较少,后续会增加一些功能;


参考资料:https://www.cnblogs.com/jianqingwang/p/7017495.html
参考资料:https://www.jianshu.com/p/343ed80b4dca
参考资料:(https://blog.csdn.net/ld0807/article/details/54178652](https://blog.csdn.net/ld0807/article/details/54178652)
原文:http://blog.isdevil.com/cjerrybird/2019/02/phpmysql%e5%ae%9e%e7%8e%b0%e7%bb%9f%e8%ae%a1%e7%bd%91%e7%ab%99%e8%ae%bf%e9%97%ae%e9%87%8f%e4%b8%80.html

你可能感兴趣的:(wordpress)