Home  >  Article  >  Backend Development  >  php gets the browser ip browser ip location operating system picture output

php gets the browser ip browser ip location operating system picture output

WBOY
WBOYOriginal
2016-07-25 08:50:191156browse
PHP obtains the browser's IP address, the operating system where the browser IP is located, and the picture output. You can visit http://www.pc811.com/ip/i.php to view the demonstration effect. Requires windows font package. The font package is placed in the directory.
  1. header("Content-type: image/png");/*State that this is a picture*/
  2. $width=350;/*Picture length*/
  3. $height=120; /*Image height*/
  4. //$_GET["editname"]
  5. $size=11;/*Font size*/
  6. $angle=0;/*Rotation degree*/
  7. $font = "simhei.ttf"; /*Set font*/
  8. $useragent=$useragent=$_SERVER['HTTP_USER_AGENT'];
  9. $signature=$_GET["signature"];//Parameters passed from URL
  10. /*Set image attributes*/
  11. $ im = imagecreatetruecolor($width, $height);
  12. /*$im = imagecreatefromjpeg("logo.png");*/
  13. $white = imagecolorallocate($im, 255, 255, 255);/*Background color* /
  14. $grey = imagecolorallocate($im, 255, 0, 0);/*Font color*/
  15. $black = imagecolorallocate($im, 0, 0, 0);
  16. /*Get the client IP address and location Region*/
  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 'Earth';
  27. }
  28. }
  29. /*Get the client browser version*/
  30. function browser($ua) {
  31. if (stripos($ua, "Googlebot")) {
  32. $browser = "Google Spider";
  33. }
  34. elseif(stripos ($ua, "Baiduspider") !== false) {
  35. $browser = "Baiduspider";
  36. }
  37. elseif(stripos($ua, "Yahoo!") !== false) {
  38. $browser = "Yahoo Spider";
  39. }
  40. elseif(stripos($ua, "bingbot")) {
  41. $browser = "Bing Spider";
  42. }
  43. elseif(stripos($ua, "YRSpider")) {
  44. $browser = " Yunnan Spider";
  45. }
  46. elseif(stripos($ua, "Yeti") !== false) {
  47. $browser = "Naver Spider";
  48. }
  49. elseif(stripos($ua, "Maxthon")) {
  50. if (stripos($ua, "AppleWebKit")) {
  51. $browser = "訨游 browser (speed mode)";
  52. }
  53. elseif(stripos($ua, "Trident")) {
  54. $browser = "訨游 browser Browser (compatibility mode)";
  55. }
  56. elseif(stripos($ua, "MAXTHON 2.0")) {
  57. $browser = "MAXTHON 2.0";
  58. }
  59. }
  60. elseif(stripos($ua, "Firefox ")) {
  61. $browser = "Firefox";
  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 = "Baidu Browser (compatibility mode)";
  69. }
  70. elseif( stripos($ua, "AppleWebKit")) {
  71. $browser = "Baidu Browser (Extreme Speed ​​Mode)";
  72. }
  73. }
  74. elseif(stripos($ua, "Ruibin")) {
  75. $browser = "Ruiying Browser";
  76. }
  77. elseif(stripos($ua, "qihu theworld")) {
  78. if (stripos($ua, "Trident")) {
  79. $browser = "World Window Browser";
  80. }
  81. elseif(stripos($ua, "AppleWebKit")) {
  82. $browser = "World Window Browser (Extreme Speed ​​Mode)";
  83. }
  84. }
  85. elseif(stripos($ua, "MetaSr")) {
  86. if ( stripos($ua, "Trident")) {
  87. $browser = "Sogou high-speed browser (compatibility mode)";
  88. }
  89. elseif(stripos($ua, "AppleWebKit")) {
  90. $browser = "Sogou high-speed browser (Extreme speed mode)";
  91. }
  92. }
  93. elseif(stripos($ua, "LBBROWSER")) {
  94. if (stripos($ua, "Trident")) {
  95. $browser = "Cheetah Browser (compatibility mode) )";
  96. }
  97. elseif(stripos($ua, "AppleWebKit")) {
  98. $browser = "Cheetah Browser (Extreme Speed ​​Mode)";
  99. }
  100. }
  101. elseif(stripos($ua, "YLMFBR")) {
  102. $browser = "115 browser";
  103. }
  104. elseif(stripos($ua, "QQBrowser")) {
  105. if (stripos($ua, "Trident")) {
  106. $browser = "QQ Browser( Compatibility mode)";
  107. }
  108. elseif(stripos($ua, "AppleWebKit")) {
  109. $browser = "QQ Browser (Extreme Speed ​​Mode)";
  110. }
  111. }
  112. elseif(stripos($ua, "TencentTraveler")) {
  113. $browser = "Tencent TT Browser";
  114. }
  115. elseif(stripos($ua, "TaoBrowser")) {
  116. if (stripos($ua, "Trident")) {
  117. $browser = "Taobao Browser (compatibility mode)" ;
  118. }
  119. elseif(stripos($ua, "AppleWebkit")) {
  120. $browser = "Taobao Browser (Extreme Speed ​​Mode)";
  121. }
  122. }
  123. elseif(stripos($ua, "CoolNovo")) {
  124. $browser = "Maple Browser";
  125. }
  126. elseif(stripos($ua, "SaaYaa")) {
  127. $browser = "Flash Browser";
  128. }
  129. elseif(stripos($ua, "360SE" )) {
  130. $browser = "360 Safe Browser";
  131. }
  132. elseif(stripos($ua, "360EE")) {
  133. if (stripos($ua, "Trident")) {
  134. $browser = "360 Extremely fast browser (compatibility mode)";
  135. }
  136. elseif(stripos($ua, "AppleWebkit")) {
  137. $browser = "360 extremely fast browser (extremely fast mode)";
  138. }
  139. }
  140. elseif(stripos($ ua, "Konqueror")) {
  141. $browser = "Konqueror";
  142. }
  143. elseif(stripos($ua, "Chrome")) {
  144. $browser = "Google Chrome";
  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 Browser";
  156. }
  157. elseif(stripos($ua, "WAP")) {
  158. $browser = "Mobile Browser";
  159. } else {
  160. $browser = $ua;
  161. }
  162. if ($browser == '') $browser = $ua;
  163. return $browser;
  164. }
  165. /*Get operating system version*/
  166. function os($ua) {
  167. $os = "";
  168. if (stripos ($ua, "Googlebot")) {
  169. $os = "Google Spider";
  170. }
  171. elseif(stripos($ua, "Baiduspider") !== false) {
  172. $os = "Baiduspider";
  173. }
  174. elseif(stripos($ua, "Yahoo!") !== false) {
  175. $os = "Yahoo Spider";
  176. }
  177. elseif(stripos($ua, "bingbot")) {
  178. $os = "must Ying Spider";
  179. }
  180. elseif(stripos($ua, "YRSpider")) {
  181. $os = "YRSpider";
  182. }
  183. elseif(stripos($ua, "Yeti") !== false) {
  184. $os = "Naver Spider";
  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 = "Unknown system";
  256. }
  257. return $os;
  258. }
  259. imagettftext($im, $size, $angle, 10, 15, $grey, $font, "Current address:".address ($_SERVER['REMOTE_ADDR']));
  260. imagettftext($im, $size, $angle, 10, 35, $grey, $font, "Current IP:".$_SERVER['REMOTE_ADDR']);
  261. imagettftext ($im, $size, $angle, 10, 55, $grey, $font, "Current browser:".browser($useragent));
  262. imagettftext($im, $size, $angle, 10, 75, $grey, $font, "Current operating system:".os($useragent));
  263. imagettftext($im, $size, $angle, 10, 95, $grey, $font, $signature!=""?$ signature: " Computer Mutual Aid Network www.pc811.com");
  264. imagepng($im);
  265. imagedestroy($im);
  266. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn