萝卜头IT论坛

搜索
查看: 4211|回复: 0
收起左侧

[水] PHP制作显示IP地址操作系统及浏览器的图片

[复制链接]
发表于 2013-5-5 16:44:05 | 显示全部楼层 |阅读模式


注:识别浏览器与操作系统的函数在不断的完善中,这里只是展示核心的思想
<?php
date_default_timezone_set('Etc/GMT-8');
$useragent=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
$info=json_decode(file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip='.$ip.'&format=json'),false);
if($info->ret==1){
if($info->province!=$info->city){
$address=$info->country.",".$info->province."(".$info->city.")  ".$info->district."  ".$info->desc;
}else{
$address=$info->country.",".$info->province."  ".$info->district."  ".$info->desc;
}
}else $address='地球';
function browser($ua){
if(stripos($ua,"Googlebot")){
$browser="谷歌蜘蛛";
}elseif(stripos($ua,"Baiduspider")!==false){
$browser="百度蜘蛛";
}elseif(stripos($ua,"Yahoo!")!==false){
$browser="雅虎蜘蛛";
}elseif(stripos($ua,"bingbot")){
$browser="必应蜘蛛";
}elseif(stripos($ua,"YRSpider")){
$browser="云壤蜘蛛";
}elseif(stripos($ua,"Yeti")!==false){
$browser="Naver蜘蛛";
}elseif(stripos($ua,"Maxthon")){
if(stripos($ua,"AppleWebKit")){
$browser ="遨游浏览器(极速模式)";
}elseif(stripos($ua,"Trident")){
$browser="遨游浏览器(兼容模式)";
}elseif(stripos($ua,"MAXTHON 2.0")){
$browser="遨游浏览器2.0";
}
}elseif(stripos($ua,"Firefox")){
$browser="火狐浏览器";
}elseif(stripos($ua,"Opera")==0&&stripos($ua,"Presto")){
$browser="Opera";
}elseif(stripos($ua,"BIDUBrowser")){
if(stripos($ua,"Trident")){
$browser="百度浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebKit")){
$browser="百度浏览器(极速模式)";
}
}elseif(stripos($ua,"Ruibin")){
$browser="瑞影浏览器";
}elseif(stripos($ua,"qihu theworld")){
if(stripos($ua,"Trident")){
$browser="世界之窗浏览器";
}elseif(stripos($ua,"AppleWebKit")){
$browser="世界之窗浏览器(极速模式)";
}
}elseif(stripos($ua,"MetaSr")){
if(stripos($ua,"Trident")){
$browser="搜狗高速浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebKit")){
$browser="搜狗高速浏览器(极速模式)";
}
}elseif(stripos($ua,"LBBROWSER")){
if(stripos($ua,"Trident")){
$browser="猎豹浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebKit")){
$browser="猎豹浏览器(极速模式)";
}
}elseif(stripos($ua,"YLMFBR")){
$browser="115浏览器";
}elseif(stripos($ua,"QQBrowser")){
if(stripos($ua,"Trident")){
$browser="QQ浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebKit")){
$browser="QQ浏览器(极速模式)";
}
}elseif(stripos($ua,"TencentTraveler")){
$browser="腾讯TT浏览器";
}elseif(stripos($ua,"TaoBrowser")){
if(stripos($ua,"Trident")){
$browser="淘宝浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebkit")){
$browser="淘宝浏览器(极速模式)";
}
}elseif(stripos($ua,"CoolNovo")){
$browser="枫树浏览器";
}elseif(stripos($ua,"SaaYaa")){
$browser="闪游浏览器";
}elseif(stripos($ua,"360SE")){
$browser="360安全浏览器";
}elseif(stripos($ua,"360EE")){
if(stripos($ua,"Trident")){
$browser="360极速浏览器(兼容模式)";
}elseif(stripos($ua,"AppleWebkit")){
$browser="360极速浏览器(极速模式)";
}
}elseif(stripos($ua,"Konqueror")){
$browser="Konqueror";
}elseif(stripos($ua,"Chrome")){
$browser="谷歌浏览器";
}elseif(stripos($ua,"Safari")){
$browser="Safari";
}elseif(stripos($ua,"MSIE")){
$ver=explode(";",substr($ua,stripos($ua,"MSIE")+5,4));
$ver=$ver[0];
$browser="IE ".$ver;
}elseif(stripos($ua,"UCWEB")){
$browser="UCWEB浏览器";
}
elseif(stripos($ua,"WAP")){
$browser="Mobile浏览器";
}else{
$browser=$ua;
}
if($browser=='')$browser=$ua;
return $browser;
}
function os($ua){
$os="";
if(stripos($ua,"Googlebot")){
$os="谷歌蜘蛛";
}elseif(stripos($ua,"Baiduspider")!==false){
$os="百度蜘蛛";
}elseif(stripos($ua,"Yahoo!")!==false){
$os="雅虎蜘蛛";
}elseif(stripos($ua,"bingbot")){
$os="必应蜘蛛";
}elseif(stripos($ua,"YRSpider")){
$os="云壤蜘蛛";
}elseif(stripos($ua,"Yeti")!==false){
$os="Naver蜘蛛";
}elseif(stripos($ua,"Windows NT")){
switch(substr($ua,stripos($ua,"Windows NT")+11,3)){
case 5.0:{
$os="Windows 2000";
break;
}
case 5.1:{
$os="Windows XP";
break;
}
case 5.2:{
$os="Windows 2003";
break;
}case 6.0:{
$os="Windows Vista/2008";
break;
}
case 6.1:{
$os="Windows 7";
break;
}
case 6.2:{
$os="Windows 8";
break;
}
default:{
$os="Windows";
break;
}
}
if(stripos($ua,"WOW64")){
$os.="(X64)";
}else{
$os.="(X86)";
}
}elseif(stripos($ua,"Android")){
$os=substr($ua,stripos($ua,"Android"),11);
}elseif(stripos($ua,"Linux")){
if(stripos($ua,"i686")){
$os="Linux X86";
}else{
$os="Linux";
}
if(stripos($ua,"X11")){
$os.="(X Window)";
}
}elseif(stripos($ua,"Macintosh")){
$os="Mac";
}elseif(stripos($ua,"IOS")){
$os="iOS";
}elseif(stripos($ua,"ZTE")){
$os="ZTE";
}elseif(stripos($ua,"Windows 98")){
$os="Windows 98";
}else{
$os="未知系统";
}
return $os;
}
header('Content-type: image/png');
$image = imagecreate(290,110);
$black = imagecolorallocate($image,0,0,0);
$white = imagecolorallocate($image,255,255,255);
$font = 'include/msyhbd.ttf';
imagettftext($image,14,0,45,20,$white,$font,"浏览器及操作系统识别");
imagettftext($image,10,0,30,40,$white,$font,"您的IP是".$ip);
imagettftext($image,10,0,30,55,$white,$font,"来自".$address);
imagettftext($image,10,0,30,70,$white,$font,"当前浏览器: ".browser($useragent));
imagettftext($image,10,0,30,85,$white,$font,"运行在 ".os($useragent)." 上");
imagettftext($image,8,0,90,98,$white,$font,"http://www.lyz810.tk");
imagettftext($image,7,0,110,109,$white,$font,"©lyz810 2012");
imagepng($image);
imagedestroy($image);
?>

回复

使用道具 举报

联系我们(Contact)|手机版|萝卜头IT论坛 ( 苏ICP备15050961号-1 )

GMT+8, 2024-5-1 19:28 , Processed in 0.114661 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表