How to obtain client browser and operating system information in php

WBOY
Release: 2016-07-25 09:04:11
Original
1234 people have browsed it
  1. //Display the browser information of the visiting user

  2. echo 'Browser: ' . determinebrowser($Agent) . '
    ';
  3. //Display the visiting user Operating system platform
  4. echo 'Platform: ' . determineplatform($Agent). '
    ';

  5. //Positive expression comparison analysis $_SERVER['HTTP_USER_AGENT'] The string in gets the information of the visiting user's browser

  6. function determinebrowser ($Agent) {
  7. $browseragent=""; //Browser
  8. $browserversion=""; //Browser version
  9. if (ereg(' MSIE ([0-9].[0-9]{1,2})',$Agent,$version)) {
  10. $browserversion=$version[1];
  11. $browseragent="Internet Explorer";
  12. } else if (ereg( 'Opera/([0-9]{1,2}.[0-9]{1,2})',$Agent,$version)) {
  13. $browserversion=$version[1] ;
  14. $browseragent="Opera";
  15. } else if (ereg( 'Firefox/([0-9.]{1,5})',$Agent,$version)) {
  16. $browserversion=$version[1 ];
  17. $browseragent="Firefox";
  18. }else if (ereg( 'Chrome/([0-9.]{1,3})',$Agent,$version)) {
  19. $browserversion=$version[ 1];
  20. $browseragent="Chrome";
  21. }
  22. else if (ereg( 'Safari/([0-9.]{1,3})',$Agent,$version)) {
  23. $browseragent=" Safari";
  24. $browserversion="";
  25. }
  26. else {
  27. $browserversion="";
  28. $browseragent="Unknown";
  29. }
  30. return $browseragent." ".$browserversion;
  31. }

  32. //Similarly obtain the information of the visiting user's browser

  33. //link: http://bbs.it-home.org
  34. function determineplatform ($Agent) {
  35. $browserplatform=='';
  36. if (eregi('win',$Agent) && strpos($Agent, '95')) {
  37. $browserplatform="Windows 95";
  38. }
  39. elseif (eregi('win 9x',$Agent) && strpos( $Agent, '4.90')) {
  40. $browserplatform="Windows ME";
  41. }
  42. elseif (eregi('win',$Agent) && ereg('98',$Agent)) {
  43. $browserplatform="Windows 98";
  44. }
  45. elseif (eregi('win',$Agent) && eregi('nt 5.0',$Agent)) {
  46. $browserplatform="Windows 2000";
  47. }
  48. elseif (eregi('win', $Agent) && eregi('nt 5.1',$Agent)) {
  49. $browserplatform="Windows XP";
  50. }
  51. elseif (eregi('win',$Agent) && eregi('nt 6.0',$Agent) ) {
  52. $browserplatform="Windows Vista";
  53. }
  54. elseif (eregi('win',$Agent) && eregi('nt 6.1',$Agent)) {
  55. $browserplatform="Windows 7";
  56. }
  57. elseif (eregi('win',$Agent) && ereg('32',$Agent)) {
  58. $browserplatform="Windows 32";
  59. }
  60. elseif (eregi('win',$Agent) && eregi(' nt',$Agent)) {
  61. $browserplatform="Windows NT";
  62. }elseif (eregi('Mac OS',$Agent)) {
  63. $browserplatform="Mac OS";
  64. }
  65. elseif (eregi(' linux',$Agent)) {
  66. $browserplatform="Linux";
  67. }
  68. elseif (eregi('unix',$Agent)) {
  69. $browserplatform="Unix";
  70. }
  71. elseif (eregi('sun' ,$Agent) && eregi('os',$Agent)) {
  72. $browserplatform="SunOS";
  73. }
  74. elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) {
  75. $browserplatform="IBM OS/2";
  76. }
  77. elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) {
  78. $browserplatform="Macintosh";
  79. }
  80. elseif ( eregi('PowerPC',$Agent)) {
  81. $browserplatform="PowerPC";
  82. }
  83. elseif (eregi('AIX',$Agent)) {
  84. $browserplatform="AIX";
  85. }
  86. elseif (eregi( 'HPUX',$Agent)) {
  87. $browserplatform="HPUX";
  88. }
  89. elseif (eregi('NetBSD',$Agent)) {
  90. $browserplatform="NetBSD";
  91. }
  92. elseif (eregi('BSD ',$Agent)) {
  93. $browserplatform="BSD";
  94. }
  95. elseif (ereg('OSF1',$Agent)) {
  96. $browserplatform="OSF1";
  97. }
  98. elseif (ereg('IRIX', $Agent)) {
  99. $browserplatform="IRIX";
  100. }
  101. elseif (eregi('FreeBSD',$Agent)) {
  102. $browserplatform="FreeBSD";
  103. }
  104. if ($browserplatform=='') { $browserplatform = "Unknown"; }
  105. return $browserplatform;
  106. }
  107. ?>

Copy code

Articles you may be interested in: PHP code to determine browser type php Get the code of the visitor’s browser php code to determine browser type, browser language and other information



source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template