文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php取得客户端信息(浏览器/IP/操作系统)

php取得客户端信息(浏览器/IP/操作系统)

时间:2007-06-10  来源:sdqdgaopeng

PHP代码:
  1. <?php
  2.  
  3. class clientGetObj
  4. {
  5. function getBrowse()
  6. {
  7. global $_SERVER;
  8. $Agent = $_SERVER['HTTP_USER_AGENT'];
  9. $browser = '';
  10. $browserver = '';
  11. $Browser = array('Lynx', 'MOSAIC', 'AOL', 'Opera', 'JAVA', 'MacWeb', 'WebExplorer', 'OmniWeb');
  12. for($i = 0; $i <= 7; $i ++){
  13. if(strpos($Agent, $Browsers[$i])){
  14. $browser = $Browsers[$i];
  15. $browserver = '';
  16. }
  17. }
  18. if(ereg('Mozilla', $Agent) && !ereg('MSIE', $Agent)){
  19. $temp = explode('(', $Agent);
  20. $Part = $temp[0];
  21. $temp = explode('/', $Part);
  22. $browserver = $temp[1];
  23. $temp = explode(' ', $browserver);
  24. $browserver = $temp[0];
  25. $browserver = preg_replace('/([d.]+)/', '1', $browserver);
  26. $browserver = $browserver;
  27. $browser = 'Netscape Navigator';
  28. }
  29. if(ereg('Mozilla', $Agent) && ereg('Opera', $Agent)) {
  30. $temp = explode('(', $Agent);
  31. $Part = $temp[1];
  32. $temp = explode(')', $Part);
  33. $browserver = $temp[1];
  34. $temp = explode(' ', $browserver);
  35. $browserver = $temp[2];
  36. $browserver = preg_replace('/([d.]+)/', '1', $browserver);
  37. $browserver = $browserver;
  38. $browser = 'Opera';
  39. }
  40. if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent)){
  41. $temp = explode('(', $Agent);
  42. $Part = $temp[1];
  43. $temp = explode(';', $Part);
  44. $Part = $temp[1];
  45. $temp = explode(' ', $Part);
  46. $browserver = $temp[2];
  47. $browserver = preg_replace('/([d.]+)/','1',$browserver);
  48. $browserver = $browserver;
  49. $browser = 'Internet Explorer';
  50. }
  51. if($browser != ''){
  52. $browseinfo = $browser.' '.$browserver;
  53. } else {
  54. $browseinfo = false;
  55. }
  56. return $browseinfo;
  57. }
  58.  
  59. function getIP ()
  60. {
  61. global $_SERVER;
  62. if (getenv('HTTP_CLIENT_IP')) {
  63. $ip = getenv('HTTP_CLIENT_IP');
  64. } else if (getenv('HTTP_X_FORWARDED_FOR')) {
  65. $ip = getenv('HTTP_X_FORWARDED_FOR');
  66. } else if (getenv('REMOTE_ADDR')) {
  67. $ip = getenv('REMOTE_ADDR');
  68. } else {
  69. $ip = $_SERVER['REMOTE_ADDR'];
  70. }
  71. return $ip;
  72. }
  73.  
  74. function getOS ()
  75. {
  76. global $_SERVER;
  77. $agent = $_SERVER['HTTP_USER_AGENT'];
  78. $os = false;
  79. if (eregi('win', $agent) && strpos($agent, '95')){
  80. $os = 'Windows 95';
  81. }
  82. else if (eregi('win 9x', $agent) && strpos($agent, '4.90')){
  83. $os = 'Windows ME';
  84. }
  85. else if (eregi('win', $agent) && ereg('98', $agent)){
  86. $os = 'Windows 98';
  87. }
  88. else if (eregi('win', $agent) && eregi('nt 5.1', $agent)){
  89. $os = 'Windows XP';
  90. }
  91. else if (eregi('win', $agent) && eregi('nt 5', $agent)){
  92. $os = 'Windows 2000';
  93. }
  94. else if (eregi('win', $agent) && eregi('nt', $agent)){
  95. $os = 'Windows NT';
  96. }
  97. else if (eregi('win', $agent) && ereg('32', $agent)){
  98. $os = 'Windows 32';
  99. }
  100. else if (eregi('linux', $agent)){
  101. $os = 'Linux';
  102. }
  103. else if (eregi('unix', $agent)){
  104. $os = 'Unix';
  105. }
  106. else if (eregi('sun', $agent) && eregi('os', $agent)){
  107. $os = 'SunOS';
  108. }
  109. else if (eregi('ibm', $agent) && eregi('os', $agent)){
  110. $os = 'IBM OS/2';
  111. }
  112. else if (eregi('Mac', $agent) && eregi('PC', $agent)){
  113. $os = 'Macintosh';
  114. }
  115. else if (eregi('PowerPC', $agent)){
  116. $os = 'PowerPC';
  117. }
  118. else if (eregi('AIX', $agent)){
  119. $os = 'AIX';
  120. }
  121. else if (eregi('HPUX', $agent)){
  122. $os = 'HPUX';
  123. }
  124. else if (eregi('NetBSD', $agent)){
  125. $os = 'NetBSD';
  126. }
  127. else if (eregi('BSD', $agent)){
  128. $os = 'BSD';
  129. }
  130. else if (ereg('OSF1', $agent)){
  131. $os = 'OSF1';
  132. }
  133. else if (ereg('IRIX', $agent)){
  134. $os = 'IRIX';
  135. }
  136. else if (eregi('FreeBSD', $agent)){
  137. $os = 'FreeBSD';
  138. }
  139. else if (eregi('teleport', $agent)){
  140. $os = 'teleport';
  141. }
  142. else if (eregi('flashget', $agent)){
  143. $os = 'flashget';
  144. }
  145. else if (eregi('webzip', $agent)){
  146. $os = 'webzip';
  147. }
  148. else if (eregi('offline', $agent)){
  149. $os = 'offline';
  150. }
  151. else {
  152. $os = 'Unknown';
  153. }
  154. return $os;
  155. }
  156.  
  157. }?>

使用方法:

1.将以上框内代码另存为getinfo.php

2.在需要地页面引入getinfo.php
?
  PHP代码:
  1. <?php incude('getinfo.php'); ?>

3. 使用之前定义的类

  PHP代码:
  1. <?php
  2. $code = new clientGetObj;
  3. $str1 = $code->getBrowse();//浏览器:
  4. $str2 = $code->getIP();//IP地址:
  5. $str3 = $code->getOS();//操作系统:
  6. echo "目标浏览器:".$str1." OS:".$str3." IP:".$str2;
  7. ?>

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载