Home Backend Development PHP Tutorial php gets the browser ip browser ip location operating system picture output

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

Jul 25, 2016 am 08:50 AM

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles