#WordPress Tutorial
, I hope it will be helpful to friends in need!
wordpress
Program modification
A brief introduction to using php mysql to implement simple visitor statistics
1.php Script
<?php //连接数据库 $conn=mysql_connect("localhost","root","root"); if(!$conn){ die("链接失败".mysql_errno()); } //设置数据库编码方式 mysql_query("set names utf8",$conn) or die(mysql_errno()); //选择数据库 mysql_select_db("wordpress",$conn) or die(mysql_errno()); $adress=$_SERVER["REMOTE_ADDR"]; //将本次访客的ip地址添加到数据库中 $sql="select times from wp_count where ip='$adress'"; $res=mysql_query($sql,$conn); if(!$row=mysql_fetch_row($res)){ $sql="insert into wp_count(ip, times) values('$adress','1')"; }else{ $times = $row['0']+1; $sql="update wp_count set times='$times' where ip='$adress'"; } $res=mysql_query($sql,$conn); //发送语句获取总数 $sql="select count(ip) from wp_count"; $res=mysql_query($sql,$conn); if($row=mysql_fetch_row($res)){ $num=$row['0']; } echo"您是第 "."$num"." 位访客"."您的ip地址是"."$adress"; mysql_close(); ?>
2. Database example
Table wp_count
ps: The above table structure meets my needs, because my site counts the number of IPs , and I regard the same IP as a visitor no matter how many times it is accessed. The number of digits displayed on the page is the total number of IP visits. ######3. Effect ### ######4. Extension######The above example is implemented using a database. Of course, it is also possible to use txt text. ######Based on simple visitor statistics, you can add a very accurate site statistics to your site. For example, to realize the visitor's last visit time, you can use js to trigger the modification of the visit time when the visitor closes the current page. ######ps: After testing, Baidu statistics are not very accurate. Because Baidu uses referenced js for data statistics, if the site js fails to load or for other reasons, some data may not be counted. #########The above is the detailed content of How to implement visitor statistics in WordPress. For more information, please follow other related articles on the PHP Chinese website!