首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
一句话概述代码的用途:
*
(例: 使用js控制复制及输入数据时只能是数字)
120
字
代码类型:
无
函数
类
插件
单段代码直接可运行
TAG标签:
(用空格隔开)
30
字
描述说明:
请填写代码的实现原理、应用场景、功能说明、调用示例、注意事项等。
关闭浏览器再会重复记录 把下面代码存入如:i.php 在html中加入如: var img = new Image(); img.src = 'i.php?w='+window.screen.width+'&h='+window.screen.availHeight;
代码正文:
*
请选择语言
html
python
javascript
php
sql
c
c++
c#
java
plain
简单说明:
排序:
测试一下
getaddress($ip); $addr=$addr['area1']."[$addr[area2]]"; file_put_contents('record.txt',"\r\n时间:$time 语言:$lang 浏览器:$browser[0] $browser[1] 操作系统:$os IP:$ip 分辨率:$w*$h 地理位置:$addr",FILE_APPEND); } ob_clean(); header("Content-type: image/png"); $im = imageCreate(1, 1); $red = imagecolorallocate($im, 255, 0, 0); imagePng ($im); //以 PNG 格式将图像输出 imageDestroy($im); /** * 时间,语言,浏览器,操作系统,IP, 分辨率 地理位置 */ function GetLang() { $Lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //使用substr()截取字符串,从 0 位开始,截取4个字符 if (preg_match('/zh-c/i',$Lang)) { //preg_match()正则表达式匹配函数 $Lang = '简体中文'; } elseif (preg_match('/zh/i',$Lang)) { $Lang = '繁體中文'; } else { $Lang = 'English'; } return $Lang; } /** * 获得浏览器名称和版本 * * @access public * @return string */ function get_brower() { if (empty($_SERVER['HTTP_USER_AGENT'])){ return false; } $agent = $_SERVER['HTTP_USER_AGENT']; $browser = ''; $browser_ver = ''; if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)){ $browser = 'Internet Explorer'; $browser_ver = $regs[1]; }elseif (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)){ $browser = 'FireFox'; $browser_ver = $regs[1]; }elseif (preg_match('/Maxthon/i', $agent, $regs)){ $browser = '(Internet Explorer ' .$browser_ver. ') Maxthon'; $browser_ver = ''; }elseif (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)){ $browser = 'Opera'; $browser_ver = $regs[1]; }elseif (preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $regs)){ $browser = 'OmniWeb'; $browser_ver = $regs[2]; }elseif (preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $regs)){ $browser = 'Netscape'; $browser_ver = $regs[2]; }elseif (preg_match('/chrome\/([^\s]+)/i', $agent, $regs)){ $browser = 'chrome'; $browser_ver = $regs[1]; }elseif (preg_match('/safari\/([^\s]+)/i', $agent, $regs)){ $browser = 'Safari'; $browser_ver = $regs[1]; }elseif (preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $regs)){ $browser = '(Internet Explorer ' .$browser_ver. ') NetCaptor'; $browser_ver = $regs[1]; }elseif (preg_match('/Lynx\/([^\s]+)/i', $agent, $regs)){ $browser = 'Lynx'; $browser_ver = $regs[1]; } if (!empty($browser)){ return array($browser,$browser_ver); }else { return false; } } /** * 获得客户端的操作系统 * * @access private * @return void */ function get_os() { if (empty($_SERVER['HTTP_USER_AGENT'])){ return 'Unknown'; } $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $os = ''; if (strpos($agent, 'win') !== false){ if (strpos($agent, 'nt 5.1') !== false){ $os = 'Windows XP'; }elseif (strpos($agent, 'nt 5.2') !== false){ $os = 'Windows 2003'; }elseif (strpos($agent, 'nt 5.0') !== false){ $os = 'Windows 2000'; }elseif (strpos($agent, 'nt 6.0') !== false){ $os = 'Windows Vista'; }elseif (strpos($agent, 'nt 6.1; wow64') !== false){ $os = 'Windows 7(64)'; }elseif (strpos($agent, 'nt 6.1') !== false){ $os = 'Windows 7'; }elseif (strpos($agent, 'nt') !== false){ $os = 'Windows NT'; }elseif (strpos($agent, 'win 9x') !== false && strpos($agent, '4.90') !== false){ $os = 'Windows ME'; }elseif (strpos($agent, '98') !== false){ $os = 'Windows 98'; }elseif (strpos($agent, '95') !== false){ $os = 'Windows 95'; }elseif (strpos($agent, '32') !== false){ $os = 'Windows 32'; }elseif (strpos($agent, 'ce') !== false){ $os = 'Windows CE'; } }elseif (strpos($agent, 'linux') !== false){ $os = 'Linux'; }elseif (strpos($agent, 'unix') !== false){ $os = 'Unix'; }elseif (strpos($agent, 'sun') !== false && strpos($agent, 'os') !== false){ $os = 'SunOS'; }elseif (strpos($agent, 'ibm') !== false && strpos($agent, 'os') !== false){ $os = 'IBM OS/2'; }elseif (strpos($agent, 'mac') !== false && strpos($agent, 'pc') !== false){ $os = 'Macintosh'; }elseif (strpos($agent, 'powerpc') !== false){ $os = 'PowerPC'; }elseif (strpos($agent, 'aix') !== false){ $os = 'AIX'; }elseif (strpos($agent, 'hpux') !== false){ $os = 'HPUX'; }elseif (strpos($agent, 'netbsd') !== false){ $os = 'NetBSD'; }elseif (strpos($agent, 'bsd') !== false){ $os = 'BSD'; }elseif (strpos($agent, 'osf1') !== false){ $os = 'OSF1'; }elseif (strpos($agent, 'irix') !== false){ $os = 'IRIX'; }elseif (strpos($agent, 'freebsd') !== false){ $os = 'FreeBSD'; }elseif (strpos($agent, 'teleport') !== false){ $os = 'teleport'; }elseif (strpos($agent, 'flashget') !== false){ $os = 'flashget'; }elseif (strpos($agent, 'webzip') !== false){ $os = 'webzip'; }elseif (strpos($agent, 'offline') !== false){ $os = 'offline'; }else { $os = 'Unknown'; } return $os; } /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */ foreach ($arr AS $ip) { $ip = trim($ip); if ($ip != 'unknown') { $realip = $ip; break; } } } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $realip = $_SERVER['HTTP_CLIENT_IP']; } else { if (isset($_SERVER['REMOTE_ADDR'])) { $realip = $_SERVER['REMOTE_ADDR']; } else { $realip = '0.0.0.0'; } } } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $realip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_CLIENT_IP')) { $realip = getenv('HTTP_CLIENT_IP'); } else { $realip = getenv('REMOTE_ADDR'); } } preg_match("/[\d\.]{7,15}/", $realip, $onlineip); $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0'; return $realip; } function GetAddIsp() { $IP = $this->GetIP(); $AddIsp = mb_convert_encoding(file_get_contents('http://open.baidu.com/ipsearch/s?tn=ipjson&wd='.$IP),'UTF-8','GBK'); //mb_convert_encoding() 转换字符编码。 if (preg_match('/noresult/i',$AddIsp)) { $AddIsp = 'None'; } else { $Sta = stripos($AddIsp,$IP) + strlen($IP) + strlen('来自'); $Len = stripos($AddIsp,'"}')-$Sta; $AddIsp = substr($AddIsp,$Sta,$Len); } $AddIsp = explode(' ',$AddIsp); return $AddIsp; } function GetAdd() { $Add = $this->GetAddIsp(); return $Add[0]; } function GetIsp() { $Isp = $this->GetAddIsp(); if ($Isp[0] != 'None' && isset($Isp[1])) { $Isp = $Isp[1]; } else { $Isp = 'None'; } return $Isp; } //* //文件头 [第一条索引的偏移量 (4byte)] + [最后一条索引的偏移地址 (4byte)] 8字节 //记录区 [结束ip (4byte)] + [地区1] + [地区2] 4字节+不定长 //索引区 [开始ip (4byte)] + [指向记录区的偏移地址 (3byte)] 7字节 //注意:使用之前请去网上下载纯真IP数据库,并改名为 "CoralWry.dat" 放到当前目录下即可. //by 查询吧 www.query8.com //* class ipLocation { var $fp; var $firstip; //第一条ip索引的偏移地址 var $lastip; //最后一条ip索引的偏移地址 var $totalip; //总ip数 //* //构造函数,初始化一些变量 //$datfile 的值为纯真IP数据库的名子,可自行修改. //* function ipLocation($datfile = "qqwry.dat"){ $this->fp=fopen($datfile,'rb'); //二制方式打开 $this->firstip = $this->get4b(); //第一条ip索引的绝对偏移地址 $this->lastip = $this->get4b(); //最后一条ip索引的绝对偏移地址 $this->totalip =($this->lastip - $this->firstip)/7 ; //ip总数 索引区是定长的7个字节,在此要除以7, register_shutdown_function(array($this,"closefp")); //为了兼容php5以下版本,本类没有用析构函数,自动关闭ip库. } //* //关闭ip库 //* function closefp(){ fclose($this->fp); } //* //读取4个字节并将解压成long的长模式 //* function get4b(){ $str=unpack("V",fread($this->fp,4)); return $str[1]; } //* //读取重定向了的偏移地址 //* function getoffset(){ $str=unpack("V",fread($this->fp,3).chr(0)); return $str[1]; } //* //读取ip的详细地址信息 //* function getstr(){ $split=fread($this->fp,1); $str=""; while (ord($split)!=0) { $str.=$split; $split=fread($this->fp,1); } return $str; } //* //将ip通过ip2long转成ipv4的互联网地址,再将他压缩成big-endian字节序 //用来和索引区内的ip地址做比较 //* function iptoint($ip){ return pack("N",intval(ip2long($ip))); } //* //获取客户端ip地址 //注意:如果你想要把ip记录到服务器上,请在写库时先检查一下ip的数据是否安全. //* function getIP() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { //获取客户端用代理服务器访问时的真实ip 地址 $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } //* //获取地址信息 //* function readaddress(){ $now_offset=ftell($this->fp); //得到当前的指针位址 $flag=$this->getflag(); switch (ord($flag)){ case 0: $address=""; break; case 1: case 2: fseek($this->fp,$this->getoffset()); $address=$this->getstr(); break; default: fseek($this->fp,$now_offset); $address=$this->getstr(); break; } return $address; } //* //获取标志1或2 //用来确定地址是否重定向了. //* function getflag(){ return fread($this->fp,1); } //* //用二分查找法在索引区内搜索ip //* function searchip($ip){ $ip=gethostbyname($ip); //将域名转成ip $ip_offset["ip"]=$ip; $ip=$this->iptoint($ip); //将ip转换成长整型 $firstip=0; //搜索的上边界 $lastip=$this->totalip; //搜索的下边界 $ipoffset=$this->lastip; //初始化为最后一条ip地址的偏移地址 while ($firstip <= $lastip){ $i=floor(($firstip + $lastip) / 2); //计算近似中间记录 floor函数记算给定浮点数小的最大整数,说白了就是四舍五也舍 fseek($this->fp,$this->firstip + $i * 7); //定位指针到中间记录 $startip=strrev(fread($this->fp,4)); //读取当前索引区内的开始ip地址,并将其little-endian的字节序转换成big-endian的字节序 if ($ip < $startip) { $lastip=$i - 1; } else { fseek($this->fp,$this->getoffset()); $endip=strrev(fread($this->fp,4)); if ($ip > $endip){ $firstip=$i + 1; } else { $ip_offset["offset"]=$this->firstip + $i * 7; break; } } } return $ip_offset; } //* //获取ip地址详细信息 //* function getaddress($ip){ $ip_offset=$this->searchip($ip); //获取ip 在索引区内的绝对编移地址 $ipoffset=$ip_offset["offset"]; $address["ip"]=$ip_offset["ip"]; fseek($this->fp,$ipoffset); //定位到索引区 $address["startip"]=long2ip($this->get4b()); //索引区内的开始ip 地址 $address_offset=$this->getoffset(); //获取索引区内ip在ip记录区内的偏移地址 fseek($this->fp,$address_offset); //定位到记录区内 $address["endip"]=long2ip($this->get4b()); //记录区内的结束ip 地址 $flag=$this->getflag(); //读取标志字节 switch (ord($flag)) { case 1: //地区1地区2都重定向 $address_offset=$this->getoffset(); //读取重定向地址 fseek($this->fp,$address_offset); //定位指针到重定向的地址 $flag=$this->getflag(); //读取标志字节 switch (ord($flag)) { case 2: //地区1又一次重定向, fseek($this->fp,$this->getoffset()); $address["area1"]=$this->getstr(); fseek($this->fp,$address_offset+4); //跳4个字节 $address["area2"]=$this->readaddress(); //地区2有可能重定向,有可能没有 break; default: //地区1,地区2都没有重定向 fseek($this->fp,$address_offset); //定位指针到重定向的地址 $address["area1"]=$this->getstr(); $address["area2"]=$this->readaddress(); break; } break; case 2: //地区1重定向 地区2没有重定向 $address1_offset=$this->getoffset(); //读取重定向地址 fseek($this->fp,$address1_offset); $address["area1"]=$this->getstr(); fseek($this->fp,$address_offset+8); $address["area2"]=$this->readaddress(); break; default: //地区1地区2都没有重定向 fseek($this->fp,$address_offset+4); $address["area1"]=$this->getstr(); $address["area2"]=$this->readaddress(); break; } //*过滤一些无用数据 if (strpos($address["area1"],"CZ88.NET")!=false){ $address["area1"]="未知"; } if (strpos($address["area2"],"CZ88.NET")!=false){ $address["area2"]=" "; } return $address; } }
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.0020301342010498 秒,PHP脚本用时 0.004026 秒,占用内存 0.544 MB,Gzip 已启用