首頁 >後端開發 >php教程 >php取得瀏覽者ip瀏覽器ip所在地作業系統 圖片輸出

php取得瀏覽者ip瀏覽器ip所在地作業系統 圖片輸出

WBOY
WBOY原創
2016-07-25 08:50:191210瀏覽
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 = "Google蜘蛛";
  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, "Cronpos($ua ")) {
  144. $browser = "Google瀏覽器";
  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 = "Google蜘蛛";
  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. {
  196. {
  197. {
  198. {
  199. {
  200. {
  201. {
  202. {
  203. {
  204. {
  205. {
  206. {
  207. 🎜> $os = "Windows XP";
  208. break;
  209. }
  210. case 5.2:
  211. {
  212. $os = "Windows 2003";
  213. break;
  214. }
  215. case 6.0:
  216. {
  217. $os = "Windows Vista/2008";
  218. break;
  219. }
  220. case 6.1:
  221. {
  222. $os = "Windows 7osos = "Windows 7 ";
  223. break;
  224. }
  225. case 6.2:
  226. {
  227. $os = "Windows 8";
  228. break;
  229. }
  230. default:
  231. {
  232. $os = "Windows";
  233. break;
  234. }
  235. }
  236. if (stripos($ua, "WOW64")) {
  237. $os.= "(X64) ";
  238. } else {
  239. $os.= "(X86)";
  240. }
  241. }
  242. elseif(stripos($ua, "Android")) {
  243. $os = substr($ua, stripos($ua, "Android"), 11);
  244. }
  245. elseif(stripos($ua, "Linux")) {
  246. if (stripos($ua, " i686")) {
  247. $os = "Linux X86";
  248. } else {
  249. $os = "Linux";
  250. }
  251. if (stripos($ua, "X11") ) {
  252. $os.= "(X Window)";
  253. }
  254. } 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 {
  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. ?>
複製程式碼


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn