欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取浏览者ip浏览器ip所在地操作系统 图片输出

程序员文章站 2022-05-26 12:59:01
...
php获取浏览者ip\浏览器\ip所在地\操作系统 图片输出 可访问http://www.pc811.com/ip/i.php查看演示效果。需要windows字体包。字体包放目录中。
  1. header("Content-type: image/png");/*声明这是一张图片*/
  2. $width=350;/*图片长度*/
  3. $height=120;/*图片高度*/
  4. //$_GET["editname"]
  5. $size=11;/*字体大小*/
  6. $angle=0;/*旋转度数*/
  7. $font = "simhei.ttf";/*设置字体*/
  8. $useragent=$useragent=$_SERVER['HTTP_USER_AGENT'];
  9. $signature=$_GET["signature"];//URL传过来的参数
  10. /*设置图片属性*/
  11. $im = imagecreatetruecolor($width, $height);
  12. /*$im = imagecreatefromjpeg("logo.png");*/
  13. $white = imagecolorallocate($im, 255, 255, 255);/*背景颜色*/
  14. $grey = imagecolorallocate($im, 255, 0, 0);/*字体颜色*/
  15. $black = imagecolorallocate($im, 0, 0, 0);
  16. /*取出客户端IP地址及所在地区*/
  17. function address($ip) {
  18. $info = json_decode(file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip='.$ip.'&format=json'), false);
  19. if ($info ->ret == 1) {
  20. if ($info ->province != $info ->city) {
  21. return $info ->country.",".$info ->province."(".$info ->city.") ".$info ->district." ".$info ->desc;
  22. } else {
  23. return $info ->country.",".$info ->province." ".$info ->district." ".$info ->desc;
  24. }
  25. } else {
  26. return '地球';
  27. }
  28. }
  29. /*取得客户端浏览器版本*/
  30. function browser($ua) {
  31. if (stripos($ua, "Googlebot")) {
  32. $browser = "谷歌蜘蛛";
  33. }
  34. elseif(stripos($ua, "Baiduspider") !== false) {
  35. $browser = "百度蜘蛛";
  36. }
  37. elseif(stripos($ua, "Yahoo!") !== false) {
  38. $browser = "雅虎蜘蛛";
  39. }
  40. elseif(stripos($ua, "bingbot")) {
  41. $browser = "必应蜘蛛";
  42. }
  43. elseif(stripos($ua, "YRSpider")) {
  44. $browser = "云壤蜘蛛";
  45. }
  46. elseif(stripos($ua, "Yeti") !== false) {
  47. $browser = "Naver蜘蛛";
  48. }
  49. elseif(stripos($ua, "Maxthon")) {
  50. if (stripos($ua, "AppleWebKit")) {
  51. $browser = "遨游浏览器(极速模式)";
  52. }
  53. elseif(stripos($ua, "Trident")) {
  54. $browser = "遨游浏览器(兼容模式)";
  55. }
  56. elseif(stripos($ua, "MAXTHON 2.0")) {
  57. $browser = "遨游浏览器2.0";
  58. }
  59. }
  60. elseif(stripos($ua, "Firefox")) {
  61. $browser = "火狐浏览器";
  62. }
  63. elseif(stripos($ua, "Opera") == 0 && stripos($ua, "Presto")) {
  64. $browser = "Opera";
  65. }
  66. elseif(stripos($ua, "BIDUBrowser")) {
  67. if (stripos($ua, "Trident")) {
  68. $browser = "百度浏览器(兼容模式)";
  69. }
  70. elseif(stripos($ua, "AppleWebKit")) {
  71. $browser = "百度浏览器(极速模式)";
  72. }
  73. }
  74. elseif(stripos($ua, "Ruibin")) {
  75. $browser = "瑞影浏览器";
  76. }
  77. elseif(stripos($ua, "qihu theworld")) {
  78. if (stripos($ua, "Trident")) {
  79. $browser = "世界之窗浏览器";
  80. }
  81. elseif(stripos($ua, "AppleWebKit")) {
  82. $browser = "世界之窗浏览器(极速模式)";
  83. }
  84. }
  85. elseif(stripos($ua, "MetaSr")) {
  86. if (stripos($ua, "Trident")) {
  87. $browser = "搜狗高速浏览器(兼容模式)";
  88. }
  89. elseif(stripos($ua, "AppleWebKit")) {
  90. $browser = "搜狗高速浏览器(极速模式)";
  91. }
  92. }
  93. elseif(stripos($ua, "LBBROWSER")) {
  94. if (stripos($ua, "Trident")) {
  95. $browser = "猎豹浏览器(兼容模式)";
  96. }
  97. elseif(stripos($ua, "AppleWebKit")) {
  98. $browser = "猎豹浏览器(极速模式)";
  99. }
  100. }
  101. elseif(stripos($ua, "YLMFBR")) {
  102. $browser = "115浏览器";
  103. }
  104. elseif(stripos($ua, "QQBrowser")) {
  105. if (stripos($ua, "Trident")) {
  106. $browser = "QQ浏览器(兼容模式)";
  107. }
  108. elseif(stripos($ua, "AppleWebKit")) {
  109. $browser = "QQ浏览器(极速模式)";
  110. }
  111. }
  112. elseif(stripos($ua, "TencentTraveler")) {
  113. $browser = "腾讯TT浏览器";
  114. }
  115. elseif(stripos($ua, "TaoBrowser")) {
  116. if (stripos($ua, "Trident")) {
  117. $browser = "淘宝浏览器(兼容模式)";
  118. }
  119. elseif(stripos($ua, "AppleWebkit")) {
  120. $browser = "淘宝浏览器(极速模式)";
  121. }
  122. }
  123. elseif(stripos($ua, "CoolNovo")) {
  124. $browser = "枫树浏览器";
  125. }
  126. elseif(stripos($ua, "SaaYaa")) {
  127. $browser = "闪游浏览器";
  128. }
  129. elseif(stripos($ua, "360SE")) {
  130. $browser = "360安全浏览器";
  131. }
  132. elseif(stripos($ua, "360EE")) {
  133. if (stripos($ua, "Trident")) {
  134. $browser = "360极速浏览器(兼容模式)";
  135. }
  136. elseif(stripos($ua, "AppleWebkit")) {
  137. $browser = "360极速浏览器(极速模式)";
  138. }
  139. }
  140. elseif(stripos($ua, "Konqueror")) {
  141. $browser = "Konqueror";
  142. }
  143. elseif(stripos($ua, "Chrome")) {
  144. $browser = "谷歌浏览器";
  145. }
  146. elseif(stripos($ua, "Safari")) {
  147. $browser = "Safari";
  148. }
  149. elseif(stripos($ua, "MSIE")) {
  150. $ver = explode(";", substr($ua, stripos($ua, "MSIE") + 5, 4));
  151. $ver = $ver[0];
  152. $browser = "IE ".$ver;
  153. }
  154. elseif(stripos($ua, "UCWEB")) {
  155. $browser = "UCWEB浏览器";
  156. }
  157. elseif(stripos($ua, "WAP")) {
  158. $browser = "Mobile浏览器";
  159. } else {
  160. $browser = $ua;
  161. }
  162. if ($browser == '') $browser = $ua;
  163. return $browser;
  164. }
  165. /*取得操作系统版本*/
  166. function os($ua) {
  167. $os = "";
  168. if (stripos($ua, "Googlebot")) {
  169. $os = "谷歌蜘蛛";
  170. }
  171. elseif(stripos($ua, "Baiduspider") !== false) {
  172. $os = "百度蜘蛛";
  173. }
  174. elseif(stripos($ua, "Yahoo!") !== false) {
  175. $os = "雅虎蜘蛛";
  176. }
  177. elseif(stripos($ua, "bingbot")) {
  178. $os = "必应蜘蛛";
  179. }
  180. elseif(stripos($ua, "YRSpider")) {
  181. $os = "云壤蜘蛛";
  182. }
  183. elseif(stripos($ua, "Yeti") !== false) {
  184. $os = "Naver蜘蛛";
  185. }
  186. elseif(stripos($ua, "Windows NT")) {
  187. switch (substr($ua, stripos($ua, "Windows NT") + 11, 3)) {
  188. case 5.0:
  189. {
  190. $os = "Windows 2000";
  191. break;
  192. }
  193. case 5.1:
  194. {
  195. $os = "Windows XP";
  196. break;
  197. }
  198. case 5.2:
  199. {
  200. $os = "Windows 2003";
  201. break;
  202. }
  203. case 6.0:
  204. {
  205. $os = "Windows Vista/2008";
  206. break;
  207. }
  208. case 6.1:
  209. {
  210. $os = "Windows 7";
  211. break;
  212. }
  213. case 6.2:
  214. {
  215. $os = "Windows 8";
  216. break;
  217. }
  218. default:
  219. {
  220. $os = "Windows";
  221. break;
  222. }
  223. }
  224. if (stripos($ua, "WOW64")) {
  225. $os.= "(X64)";
  226. } else {
  227. $os.= "(X86)";
  228. }
  229. }
  230. elseif(stripos($ua, "Android")) {
  231. $os = substr($ua, stripos($ua, "Android"), 11);
  232. }
  233. elseif(stripos($ua, "Linux")) {
  234. if (stripos($ua, "i686")) {
  235. $os = "Linux X86";
  236. } else {
  237. $os = "Linux";
  238. }
  239. if (stripos($ua, "X11")) {
  240. $os.= "(X Window)";
  241. }
  242. }
  243. elseif(stripos($ua, "Macintosh")) {
  244. $os = "Mac";
  245. }
  246. elseif(stripos($ua, "IOS")) {
  247. $os = "iOS";
  248. }
  249. elseif(stripos($ua, "ZTE")) {
  250. $os = "ZTE";
  251. }
  252. elseif(stripos($ua, "Windows 98")) {
  253. $os = "Windows 98";
  254. } else {
  255. $os = "未知系统";
  256. }
  257. return $os;
  258. }
  259. imagettftext($im, $size, $angle, 10, 15, $grey, $font, "当前地址:".address($_SERVER['REMOTE_ADDR']));
  260. imagettftext($im, $size, $angle, 10, 35, $grey, $font, "当前IP:".$_SERVER['REMOTE_ADDR']);
  261. imagettftext($im, $size, $angle, 10, 55, $grey, $font, "当前浏览器:".browser($useragent));
  262. imagettftext($im, $size, $angle, 10, 75, $grey, $font, "当前操作系统:".os($useragent));
  263. imagettftext($im, $size, $angle, 10, 95, $grey, $font, $signature!=""?$signature:"  电脑互助网 www.pc811.com");
  264. imagepng($im);
  265. imagedestroy($im);
  266. ?>
复制代码