PHP统计WordPress博客网站在线人数代码,把代码添加到你要添加的地方,注知更鸟主题直接添加一个增强版的php小工具放入以下代码即可,添加后会自动创建一个maplers.dat文件,请不要乱动。
WordPress统计网站在线人数代码
- <?php
- $online_log = "maplers.dat";
- $timeout = 30;
- $entries = file($online_log);
- $temp = array();
- for ($i=0;$i<count($entries);$i++){
- $entry = explode(",",trim($entries[$i]));
- if(($entry[0] != getenv('REMOTE_ADDR')) && ($entry[1] > time())) {
- array_push($temp,$entry[0].",".$entry[1]."\n");
- }}
- array_push($temp,getenv('REMOTE_ADDR').",".(time() + ($timeout))."\n");
- $maplers = count($temp);
- $entries = implode("",$temp);
- $fp = fopen($online_log,"w");
- flock($fp,LOCK_EX);
- fputs($fp,$entries);
- flock($fp,LOCK_UN);
- fclose($fp);
- echo "在线人数:".$maplers."人";
- ?>
还不会用请到下面留言,代码来自小墨渊