fork(1) download
  1. <?php
  2.  
  3. $user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36";
  4.  
  5. function getOS() {
  6.  
  7. global $user_agent;
  8.  
  9. $os_platform = "Unknown OS Platform";
  10.  
  11. $os_array = array(
  12. '/windows nt 10.0/i' => 'Windows 10',
  13. '/windows nt 6.2/i' => 'Windows 8',
  14. '/windows nt 6.1/i' => 'Windows 7',
  15. '/windows nt 6.0/i' => 'Windows Vista',
  16. '/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
  17. '/windows nt 5.1/i' => 'Windows XP',
  18. '/windows xp/i' => 'Windows XP',
  19. '/windows nt 5.0/i' => 'Windows 2000',
  20. '/windows me/i' => 'Windows ME',
  21. '/win98/i' => 'Windows 98',
  22. '/win95/i' => 'Windows 95',
  23. '/win16/i' => 'Windows 3.11',
  24. '/macintosh|mac os x/i' => 'Mac OS X',
  25. '/mac_powerpc/i' => 'Mac OS 9',
  26. '/linux/i' => 'Linux',
  27. '/ubuntu/i' => 'Ubuntu',
  28. '/iphone/i' => 'iPhone',
  29. '/ipod/i' => 'iPod',
  30. '/ipad/i' => 'iPad',
  31. '/android/i' => 'Android',
  32. '/blackberry/i' => 'BlackBerry',
  33. '/webos/i' => 'Mobile'
  34. );
  35.  
  36. foreach ($os_array as $regex => $value) {
  37.  
  38. if (preg_match($regex, $user_agent)) {
  39. $os_platform = $value;
  40. }
  41.  
  42. }
  43.  
  44. return $os_platform;
  45.  
  46. }
  47.  
  48. function getBrowser() {
  49.  
  50. global $user_agent;
  51.  
  52. $browser = "Unknown Browser";
  53.  
  54. $browser_array = array(
  55. '/msie/i' => 'Internet Explorer',
  56. '/firefox/i' => 'Firefox',
  57. '/safari/i' => 'Safari',
  58. '/chrome/i' => 'Chrome',
  59. '/opera/i' => 'Opera',
  60. '/netscape/i' => 'Netscape',
  61. '/maxthon/i' => 'Maxthon',
  62. '/konqueror/i' => 'Konqueror',
  63. '/mobile/i' => 'Handheld Browser'
  64. );
  65.  
  66. foreach ($browser_array as $regex => $value) {
  67.  
  68. if (preg_match($regex, $user_agent)) {
  69. $browser = $value;
  70. }
  71.  
  72. }
  73.  
  74. return $browser;
  75.  
  76. }
  77.  
  78.  
  79. $user_os = getOS();
  80. $user_browser = getBrowser();
  81.  
  82. $device_details = "<strong>Browser: </strong>".$user_browser."<br /> <strong>Operating System: </strong>".$user_os."";
  83.  
  84. print_r($device_details);
  85.  
  86. echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");
  87.  
  88. ?>
Success #stdin #stdout #stderr 0.02s 52472KB
stdin
Standard input is empty
stdout
<strong>Browser: </strong>Chrome<br />                <strong>Operating System: </strong>Windows 10<br /><br /><br />
stderr
PHP Notice:  Undefined index: HTTP_USER_AGENT in /home/GxMLij/prog.php on line 86