国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

php實現統計IP數及在線人數的示例代碼

瀏覽:103日期:2022-09-09 14:43:18

寫在前面的話

很多人有這樣的需求,就是統計網站訪問IP以及在線的人數。今天我們就看一下具體實現方法。

開啟依賴函數模塊

實現這個功能,需要依賴putenv()函數。下面兩種方式均可。

更改php.ini文件方法

找到php.ini文件,搜索putenv關鍵字,刪除即可。

isable_functions = passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv

使用寶塔面板

點擊左側軟件管理,找到php,然后設置->禁用函數。

php實現統計IP數及在線人數的示例代碼

刪除putenv,然后重啟php即可。

實現函數

在count.php同目錄下創建文件:count,temp,online。新建文本文檔count.txt,去掉擴展名即為count了;

linux系統中請設置文件屬性為:777。

文件count.php代碼,用到了php函數--explode、isset、empty及sprintf等:

<?php$file = 'count'; // 記數文件名稱$startno = '1000'; // 起始數值$tempfile = 'temp'; $t_now = time();$t_array = getdate($t_now);$day = $t_array[’mday’];$mon = $t_array[’mon’];$year = $t_array[’year’];if (file_exists('$file')) { $count_info=file('$file'); $c_info = explode(',', $count_info[0]); $total_c=$c_info[0]; $yesterday_c=$c_info[1]; $today_c=$c_info[2]; $lastday=$c_info[3];} else { $total_c='$startno'; $yesterday_c='0'; $today_c='0'; $lastday='0';} if ( !isset($HTTP_COOKIE_VARS['countcookie']) || $HTTP_COOKIE_VARS['countcookie'] != $day) { $your_c=1; $lockfile=fopen('temp','a'); flock($lockfile,3); putenv(’TZ=JST-9’); $t_array2 = getdate($t_now-24*3600); $day2=$t_array2[’mday’]; $mon2=$t_array2[’mon’]; $year2=$t_array2[’year’]; $today = '$year-$mon-$day'; $yesterday = '$year2-$mon2-$day2'; if ($today != $lastday) { if ($yesterday != $lastday) $yesterday_c = '0'; else $yesterday_c = $today_c; $today_c = 0;$lastday = $today; } $total_c++; $today_c++; $total_c = sprintf('%06d', $total_c); $today_c = sprintf('%06d', $today_c); $yesterday_c = sprintf('%06d', $yesterday_c); setcookie('countcookie','$day',$t_now+43200); $fp=fopen('$file','w'); fputs($fp, '$total_c,$yesterday_c,$today_c,$lastday'); fclose($fp); fclose($lockfile);}if ( empty( $your_c ) ) $your_c = 1;setcookie('yourcount',$your_c+1,$t_now+43200);$your_c = sprintf('%06d', $your_c);//////////////////////////開始統計在線$filename='online';$onlinetime=600; //同一IP在線時間,單位:秒$online_id=file($filename);$total_online=count($online_id);$ip=getenv('REMOTE_ADDR');$nowtime=time(); for($i=0;$i<$total_online;$i++){ $oldip=explode('||',$online_id[$i]); $hasonlinetime=$nowtime-$oldip[0]; if($hasonlinetime<$onlinetime and $ip!=$oldip[1]) $nowonline[]=$online_id[$i]; } $nowonline[]=$nowtime.'||'.$ip.'||'; $total_online=count($nowonline); $fp=fopen($filename,'w'); rewind($fp); for($i=0;$i<$total_online;$i++){ fputs($fp,$nowonline[$i]); fputs($fp,'n'); } fclose($fp); if($total_online==0)$total_online=1;$total_online = sprintf('%06d', $total_online);///////////////////////////////////////////////////////echo 'document.write('·總IP訪問:'.$total_c.'');';echo 'document.write('<br>');';echo 'document.write('·昨日訪問:'.$yesterday_c.'');';echo 'document.write('<br>');';echo 'document.write('今日IP:'.$today_c.'');';echo 'document.write('&nbsp;');';echo 'document.write('·您 訪 問:'.$your_c.'');';echo 'document.write('<br>');';echo 'document.write('當前在線:'.$total_online.'');';exit;?>

php實現統計IP數及在線人數的示例代碼

調用

用JS調用文件count.php

在需要加入統計的的地方,添加:

<script src='http://www.intensediesel.com/php/count.php'></script>

到此這篇關于php實現統計IP數及在線人數的示例代碼的文章就介紹到這了,更多相關php 統計IP數及在線人數內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: PHP
相關文章:
主站蜘蛛池模板: 肇州县| 延长县| 定日县| 麻阳| 利津县| 南部县| 虞城县| 鄂托克旗| 福泉市| 色达县| 建湖县| 卓尼县| 延寿县| 赣州市| 渭南市| 阿图什市| 兴仁县| 哈巴河县| 海南省| 时尚| 乐东| 兴宁市| 双辽市| 安新县| 太仆寺旗| 东乡族自治县| 沁阳市| 北票市| 永昌县| 兴隆县| 定陶县| 镇坪县| 盱眙县| 上蔡县| 牟定县| 内江市| 荣成市| 鄂温| 台北县| 都兰县| 绥德县|