可以记录访客的地理位置,操作系统,浏览器,IP,时间和访问的文件。

1.首先创建一个comm_function.php文件:

//echo $_SERVER['HTTP_USER_AGENT'];

//echo "
".$_SERVER ['REMOTE_ADDR'];

/**

* 获取客户端类型,手机还是电脑,以及相应的操作系统类型。

*

* @param string $subject

*/

function get_os($agent) {

$os = false;

if (preg_match ( '/win/i', $agent ) && strpos ( $agent, '95' )) {

$os = 'Windows 95';

} else if (preg_match ( '/win 9x/i', $agent ) && strpos ( $agent, '4.90' )) {

$os = 'Windows ME';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/98/i', $agent )) {

$os = 'Windows 98';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.0/i', $agent )) {

$os = 'Windows Vista';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.1/i', $agent )) {

$os = 'Windows 7';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.2/i', $agent )) {

$os = 'Windows 8';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 10.0/i', $agent )) {

$os = 'Windows 10'; // 添加win10判断

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 5.1/i', $agent )) {

$os = 'Windows XP';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 5/i', $agent )) {

$os = 'Windows 2000';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt/i', $agent )) {

$os = 'Windows NT';

} else if (preg_match ( '/win/i', $agent ) && preg_match ( '/32/i', $agent )) {

$os = 'Windows 32';

} else if (preg_match ( '/linux/i', $agent )) {

if(preg_match("/Mobile/", $agent)){

if(preg_match("/QQ/i", $agent)){

$os = "Android QQ Browser";

}else{

$os = "Android Browser";

}

}else{

$os = 'PC-Linux';

}

} else if (preg_match ( '/Mac/i', $agent )) {

if(preg_match("/Mobile/", $agent)){

if(preg_match("/QQ/i", $agent)){

$os = "IPhone QQ Browser";

}else{

$os = "IPhone Browser";

}

}else{

$os = 'Mac OS X';

}

} else if (preg_match ( '/unix/i', $agent )) {

$os = 'Unix';

} else if (preg_match ( '/sun/i', $agent ) && preg_match ( '/os/i', $agent )) {

$os = 'SunOS';

} else if (preg_match ( '/ibm/i', $agent ) && preg_match ( '/os/i', $agent )) {

$os = 'IBM OS/2';

} else if (preg_match ( '/Mac/i', $agent ) && preg_match ( '/PC/i', $agent )) {

$os = 'Macintosh';

} else if (preg_match ( '/PowerPC/i', $agent )) {

$os = 'PowerPC';

} else if (preg_match ( '/AIX/i', $agent )) {

$os = 'AIX';

} else if (preg_match ( '/HPUX/i', $agent )) {

$os = 'HPUX';

} else if (preg_match ( '/NetBSD/i', $agent )) {

$os = 'NetBSD';

} else if (preg_match ( '/BSD/i', $agent )) {

$os = 'BSD';

} else if (preg_match ( '/OSF1/i', $agent )) {

$os = 'OSF1';

} else if (preg_match ( '/IRIX/i', $agent )) {

$os = 'IRIX';

} else if (preg_match ( '/FreeBSD/i', $agent )) {

$os = 'FreeBSD';

} else if (preg_match ( '/teleport/i', $agent )) {

$os = 'teleport';

} else if (preg_match ( '/flashget/i', $agent )) {

$os = 'flashget';

} else if (preg_match ( '/webzip/i', $agent )) {

$os = 'webzip';

} else if (preg_match ( '/offline/i', $agent )) {

$os = 'offline';

} else {

$os = '未知操作系统';

}

return $os;

}

/**

* 获取 客户端的浏览器类型

* @return string

*/

function get_broswer($sys){

if (stripos($sys, "Firefox/") > 0) {

preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);

$exp[0] = "Firefox";

$exp[1] = $b[1]; //获取火狐浏览器的版本号

} elseif (stripos($sys, "Maxthon") > 0) {

preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou);

$exp[0] = "傲游";

$exp[1] = $aoyou[1];

} elseif (stripos($sys, "MSIE") > 0) {

preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);

$exp[0] = "IE";

$exp[1] = $ie[1]; //获取IE的版本号

} elseif (stripos($sys, "OPR") > 0) {

preg_match("/OPR\/([\d\.]+)/", $sys, $opera);

$exp[0] = "Opera";

$exp[1] = $opera[1];

} elseif(stripos($sys, "Edge") > 0) {

//win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配

preg_match("/Edge\/([\d\.]+)/", $sys, $Edge);

$exp[0] = "Edge";

$exp[1] = $Edge[1];

} elseif (stripos($sys, "Chrome") > 0) {

preg_match("/Chrome\/([\d\.]+)/", $sys, $google);

$exp[0] = "Chrome";

$exp[1] = $google[1]; //获取google chrome的版本号

} elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){

preg_match("/rv:([\d\.]+)/", $sys, $IE);

$exp[0] = "IE";

$exp[1] = $IE[1];

}else {

$exp[0] = "未知浏览器";

$exp[1] = "";

}

return $exp[0].'('.$exp[1].')';

}

/**

* 根据 客户端IP 获取到其具体的位置信息

* @param unknown $ip

* @return string

*/

function get_address_by_ip($ip) {

$url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_HEADER, 0);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$info = curl_exec($curl);

curl_close($curl);

return $info;

}

function clientlog() {

$useragent = $_SERVER ['HTTP_USER_AGENT'];

$clientip = $_SERVER ['REMOTE_ADDR'];

$client_info = get_os ( $useragent ) . "---" . get_broswer ( $useragent );

$rawdata_position = get_address_by_ip ( $clientip );

$rawdata_position = json_decode($rawdata_position, true);

$country = $rawdata_position['data']['country'];

$province = $rawdata_position['data']['region'];

$city = $rawdata_position['data']['city'];

$nettype = $rawdata_position['data']['isp'];

$time = date ( 'y-m-d h:m:s' );

$data = "来自{$country} {$province} {$city }{$nettype} 的客户端: {$client_info},IP为:{$clientip},在{$time}时刻访问了{$_SERVER['PHP_SELF']}文件!\r\n";

$filename = "./log.log";

if (! file_exists ( $filename )) {

fopen ( $filename, "w+" );

}

file_put_contents ( $filename, $data, FILE_APPEND );

}

2.在别的文件引入这个comm_function.php

require_once "comm_function.php";

以上这篇PHP 记录访客的浏览信息方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

php网页抓取浏览者手机号码_PHP 记录访客的浏览信息方法相关推荐

  1. php监控访客_PHP 记录访客的浏览信息方法

    下面小编就为大家分享一篇PHP 记录访客的浏览信息方法,具有很好的参考和学习PHP价值,希望对大家有所帮助.对PHP感兴趣的一起跟随小编过来看看吧 可以记录访客的地理位置,操作系统,浏览器,IP,时间 ...

  2. PHP 记录访客的浏览信息

    可以记录访客的地理位置,操作系统,浏览器,IP,时间和访问的文件. 1.首先创建一个comm_function.php文件: <?php //echo $_SERVER['HTTP_USER_A ...

  3. php网页抓取浏览者手机号码_微信小程序开发之获取用户手机号码(php接口解密)...

    后边要做一个微信小程序,并要能获取用户微信绑定的手机号码.而小程序开发文档上边提供的获取手机号码的接口(getPhoneNumber())返回的是密文,需要服务器端进行解密,但是官方提供的开发文档一如 ...

  4. 使用php简单网页抓取和内容分析,使用PHP简单网页抓取和内容分析_php

    没事的时候想抓取点网页看看,也不太懂,只是玩玩,写了点代码,聊以娱乐. 稍微有点意义的函数是:get_content_by_socket(), get_url(), get_content_url() ...

  5. 网站如何记录访客的个人信息?

    大多数网站都会带有留言或者评论功能,那么访客在留言或者评论时肯定要记录访客的个人信息!这样访客在下一次访问网站时不需要再次填写个人信息,直接评论就ok啦!那么怎么记录访客的个人信息呢? 一.利用coo ...

  6. python爬虫怎么爬同一个网站的多页数据-如何用Python爬数据?(一)网页抓取

    如何用Python爬数据?(一)网页抓取 你期待已久的Python网络数据爬虫教程来了.本文为你演示如何从网页里找到感兴趣的链接和说明文字,抓取并存储到Excel. 需求 我在公众号后台,经常可以收到 ...

  7. 有关网页抓取问题的一些经验总结 - passover【毕成功的博客】 - 51CTO技术博客

    有关网页抓取问题的一些经验总结 - passover[毕成功的博客] - 51CTO技术博客 有关网页抓取问题的一些经验总结 2011-05-05 18:07:38 标签:爬虫 网页抓取 在写爬虫的时 ...

  8. 代理服务器ip地址如何获得_详细教程:如何使用代理服务器进行网页抓取?

    全文共2136字,预计学习时长7分钟 图源:Unsplash 万维网是数据的宝库.大数据的易得性.数据分析软件的迅猛发展以及日益廉价的计算能力进一步提高了数据驱动战略对竞争差异化的重要性. 据Forr ...

  9. ip代理服务器软件25探索云速捷_使用代理进行Web网页抓取的基础

    该全球网络是数据的宝库.大数据的可用性,数据分析软件的迅猛发展以及日益廉价的计算能力,进一步提高了数据驱动型战略对竞争差异化的重要性. 根据Forrester的报告,数据驱动型公司利用其整个组织的洞察 ...

最新文章

  1. maven 主工程 java_Maven创建Java Application工程(既jar包)
  2. python输入两个整数按先大后小的顺序输出_指针变量:输入a和b两个整数,按先大后小的顺序输出a和b。...
  3. 卡尔曼滤波(Calman Filter)基本原理
  4. Java预科篇2-环境搭建
  5. ant vue 离线文档_超全离线开发手册
  6. python编程(深拷贝和浅拷贝)
  7. 移动端页面开发通用问题解决方案
  8. android手机无法开机自动启动,手机无法开机怎么刷机?安卓手机救砖教程
  9. printer: PJL
  10. 实现童年梦想——RPG游戏入门(RPG制作大师使用教程)
  11. windows7系统损坏修复_火绒安全警报:微软发布高危漏洞补丁 火绒“漏洞修复”模块已完成升级...
  12. matlab 光斑质心算法,关于激光探测器光斑质心算法硬件的设计
  13. 配置计算机老是重启,电脑无缘无故重启是什么原因_电脑老是无故自动重启如何解决-win7之家...
  14. coldfusion php,coldfusion在php中解密
  15. Excel 序号自动增加
  16. STING 与 cGAS的结合导致TBK1 激酶募集和活化
  17. 降低指定进程的CPU占用率(适合游戏多开)
  18. 怎么把音乐从电脑传到苹果手机?电脑mp3导入苹果手机
  19. 针对Mrpt/build中的make时u出现的问题ccache: error: Failed to create temporary file for /home/jyy/.ccache/tmp/tm
  20. AngularJs - Javascript MVC 框架

热门文章

  1. ARC060 C - Tak and Cards(dp,背包)
  2. 《Shiro+Json Web Token》----用多线程优化登录
  3. MySQL数据库——检索数据(一)
  4. 定类,定序,定距,定比四种数据类型 1
  5. html段落设置宽度,html – 包裹图像时的CSS段落最小宽度
  6. 基于分解的改进型双目樽海鞘算法在有多辆自动导引车的柔性制造蜂窝环境中的绿色调度问题
  7. matlab打开pcm文件格式,用MATLAB实现PCM编码
  8. jmeter定时器的使用_jmeter定时器
  9. 超详细!操作系统实验三 系统调用(哈工大李治军)
  10. 世界随机迷宫:客户端需求整理