这种一款可以统计你网站当前在线人数的代码,由php+txt实现的无需数据来来支持,PHP+txt实例代码如下:
- <?php
- $time = gettimeofday(void);
-
- if(@filesize("time.text")<=0){
- $fd_time = fopen("time.text","w+");
- fputs($fd_time,$time[sec]);
- fclose($fd_time);
- $fd_time = fopen("ip.text","w+");
- fclose($fd_time);
- }
-
-
-
- $tamp = file("time.text");
- $equal = ($time[sec] - $tamp[0]);
- if($equal > 60){
- $fd_time = fopen("time.text","w+");
- fputs($fd_time,"");
- fclose($fd_time);
- }
-
-
-
- $fd_ip = fopen("ip.text","a+");
-
- if ($http_server_vars["http_x_forwarded_for"])
- {
- $ip = $http_server_vars["http_x_forwarded_for"];
- }
- elseif ($http_server_vars["http_client_ip"])
- {
- $ip = $http_server_vars["http_client_ip"];
- }
- elseif ($http_server_vars["remote_addr"])
- {
- $ip = $http_server_vars["remote_addr"];
- }
- elseif (getenv("http_x_forwarded_for"))
- {
- $ip = getenv("http_x_forwarded_for");
- }
- elseif (getenv("http_client_ip"))
- {
- $ip = getenv("http_client_ip");
- }
- elseif (getenv("remote_addr"))
- {
- $ip = getenv("remote_addr");
- }
- else
- {
- $ip = "unknown";
- }
-
- $ip_adds = file("ip.text");
- for($i;$i<count($ip_adds);$i++){
- if($ip." "==$ip_adds[$i]){
- $ip_check = 1;
- break;
- }
- }
- if($ip_check!=1){
- fputs($fd_ip,$ip." ");
- }
- fclose($fd_ip);
-
-
- $ip_adds = count(file("ip.text"));
- ?>
调用方法:
- <?php
-
-
-
-
-
-
- ?>
- <?php
- include("online.php");
- $fd_ip = file("ip.text");
- ?>
- <title>在线人数</title>
- <center><font color=blue size=6>php100论坛在线总人数为:<font color=red size=8><?=$ip_adds?>08610071</font>人<br>
- 用户ip:<?
- echo "<select>";
- for($i = 0;$i < count($ip_adds);$i++){
- echo"<option value = '$i'>".substr($fd_ip[$i],0,0-strlen(strrchr($fd_ip[$i],'.'))).".*</option> ";
- }
- echo "</select>";
- ?></font></center>
|