php怎样在线人数统筹和用户IP数?
发布时间:2022-04-20 08:48:14 所属栏目:语言 来源:互联网
导读:我们在访问一些网站的时候,常常会看到在线人数是多少。其实通过统计用户IP数以及在线人数,不仅能够帮助管理人员了解用户的访问和使用情况,而且展示网站在线人数,在某种程度上能够给用户一种认同感。那么PHP是如何实现统计IP 和在线人数的呢?下面是具体
我们在访问一些网站的时候,常常会看到在线人数是多少。其实通过统计用户IP数以及在线人数,不仅能够帮助管理人员了解用户的访问和使用情况,而且展示网站在线人数,在某种程度上能够给用户一种认同感。那么PHP是如何实现统计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,然后设置->禁用函数。 删除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")) { $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); //////////////////////////开始统计在线 (编辑:开发网_开封站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |