php实现统计IP数及在线人数

原文地址:https://www.wjcms.net/archives/php%E5%AE%9E%E7%8E%B0%E7%BB%9F%E8%AE%A1ip%E6%95%B0%E5%8F%8A%E5%9C%A8%E7%BA%BF%E4%BA%BA%E6%95%B0

写在前面的话

很多人有这样的需求,就是统计网站访问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数及在线人数_第1张图片 删除putenv,然后重启php即可。

实现函数

在count.php同目录下创建文件:count,temp,online。新建文本文档count.txt,去掉扩展名即为count了; linux系统中请设置文件属性为:777。 文件count.php代码,用到了php函数--explode、isset、empty及sprintf等:

");";
echo "document.write("·昨日访问:".$yesterday_c."");";
echo "document.write("
");"; echo "document.write("今日IP:".$today_c."");"; echo "document.write(" ");"; echo "document.write("·您 访 问:".$your_c."");"; echo "document.write("
");"; echo "document.write("当前在线:".$total_online."");"; exit; ?>

php实现统计IP数及在线人数_第2张图片

调用

用JS调用文件count.php 在需要加入统计的的地方,添加:

你可能感兴趣的:(php实现统计IP数及在线人数)