当前位置:Gxlcms > PHP教程 > php获取网站地理位置及操作系统信息的代码分享

php获取网站地理位置及操作系统信息的代码分享

时间:2021-07-01 10:21:17 帮助过:20人阅读

本文介绍下,用php获取网站的地理位置,以及操作系统相关信息的一例代码,有需要的朋友参考下。

1,php代码部分

  1. <!--?php
  2. /**
  3. * 获取网站地理位置
  4. * 获取网站操作系统信息
  5. * edit by bbs.it-home.org
  6. */
  7. error_reporting(E_ERROR);
  8. header(“content-Type: text/html; charset=gb2312″);
  9. set_time_limit(120);
  10. $host = isset($_POST['url']) ? chop(str_replace(‘http://’,”,$_POST['url'])) : ‘ www.2cto.com ’;
  11. $port = isset($_POST['duankou']) ? chop($_POST['duankou']) : ’80′;
  12. $num = 10;
  13. function microtime_float()
  14. {
  15. list($usec, $sec) = explode(” “, microtime());
  16. return ((float)$usec + (float)$sec);
  17. }
  18. function ip138($url)
  19. {
  20. $host = ‘www.ip138.com’;
  21. $fp = @fsockopen($host,80,&$errno,&$errstr,3);
  22. $get = “GET /ips.asp?ip=”.$url.” HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
  23. @fputs($fp,$get);
  24. $data = ”;
  25. while ($fp && !feof($fp))
  26. $data .= fread($fp, 1024);
  27. @fclose($fp);
  28. $s1 = ‘\<table width\=\”80\%\” border\=\”0\” align\=\”center”\ cellpadding\=\”0\” cellspacing\=\”0\”\-->’;
  29. $s2 = ‘\<\/table\>’;
  30. $tmp = array();
  31. preg_match_all(“/”.$s1.”([^~]*?)”.$s2.”/i”,$data,$tmp);
  32. $tmp1 = array();
  33. preg_match_all(“/\<li\>([^~]*?)\<\/li\>/i”,$tmp[0][0],$tmp1);
  34. return $tmp1[0][0].$tmp1[0][1].$tmp1[0][2];
  35. }
  36. function getsoft($host,$port)
  37. {
  38. $fp = @fsockopen($host,$port,&$errno,&$errstr,3);
  39. if(!$fp) return ‘unknown’;
  40. $get = “GET / HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
  41. @fputs($fp,$get);
  42. $data = ”;
  43. while ($fp && !feof($fp))
  44. $data .= fread($fp, 1024);
  45. @fclose($fp);
  46. $array = explode(“\n”,$data);
  47. $k = 2;
  48. for($i = 0;$i < 20;$i++)
  49. {
  50. if(stristr($array[$i],’Server’)){$k = $i; break;}
  51. }
  52. if(!stristr($array[$k],’Server’)) return ‘unknown’;
  53. else return str_replace(‘Server’,'服务器软件’,$array[$k]);
  54. }
  55. function ping($host,$port)
  56. {
  57. $time_start = microtime_float();
  58. $ip = gethostbyname($host);
  59. $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
  60. if(!$fp) return ‘Request timed out.<br>’.”\r\n”;
  61. $get = “GET / HTTP/1.1\r\nHost:”.$host.”\r\nConnection: Close\r\n\r\n”;
  62. @fputs($fp,$get);
  63. @fclose($fp);
  64. $time_end = microtime_float();
  65. $time = $time_end – $time_start;
  66. $time = ceil($time * 1000);
  67. return ‘Reply from ‘.$ip.’: time=’.$time.’ms<br>’;
  68. }
  69. if(isset($_POST['url']) && isset($_POST['duankou']))
  70. {
  71. echo ip138($host).’<br><br>’;
  72. echo ‘<font color="”#FF0000″">’.getsoft($host,$port).’</font><br><br>’;
  73. echo ‘Pinging ‘.$host.’ ['.gethostbyname($host).'] with Port:’.$port.’ of data:<br><br>’.”\r\n”;
  74. ob_flush();
  75. flush();
  76. for($i = 0;$i < $num;$i++)
  77. {
  78. echo ping($host,$port);
  79. ob_flush();
  80. flush();
  81. sleep(1);
  82. }
  83. }
  84. ?></li\>

2,页面内容部分

>>> 您可能感兴趣的文章: php新浪接口查询ip地理位置 php腾讯ip分享计划获取IP地理位置 php通过IP获取地理位置 PHP通过IP获取地理位置的代码 php通过IP获取地理位置的实例参考 php 获取用户真实IP与地理位置(淘宝IP接口)的实现代码 php根据IP地址获取当前地理位置接口

人气教程排行