PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/www/checkbrowser.php

https://gitlab.com/kim.carter/dpr
PHP | 142 lines | 120 code | 11 blank | 11 comment | 18 complexity | a61752ec0faf274fcb876ab073984300 MD5 | raw file
  1. <?php
  2. function getBrowser()
  3. {
  4. $u_agent = $_SERVER['HTTP_USER_AGENT'];
  5. $bname = 'Unknown';
  6. $platform = 'Unknown';
  7. $version= "";
  8. $ub="";
  9. //First get the platform?
  10. if (preg_match('/linux/i', $u_agent)) {
  11. $platform = 'Linux';
  12. }
  13. elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
  14. $platform = 'MacOS';
  15. }
  16. elseif (preg_match('/windows|win32/i', $u_agent)) {
  17. $platform = 'Windows';
  18. }
  19. // Next get the name of the useragent yes seperately and for good reason
  20. if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
  21. {
  22. $bname = 'Internet Explorer';
  23. $ub = "MSIE";
  24. }
  25. elseif(preg_match('/Firefox/i',$u_agent))
  26. {
  27. $bname = 'Mozilla Firefox';
  28. $ub = "Firefox";
  29. }
  30. elseif(preg_match('/Chrome/i',$u_agent))
  31. {
  32. $bname = 'Google Chrome';
  33. $ub = "Chrome";
  34. }
  35. elseif(preg_match('/Safari/i',$u_agent))
  36. {
  37. $bname = 'Apple Safari';
  38. $ub = "Safari";
  39. }
  40. elseif(preg_match('/Opera/i',$u_agent))
  41. {
  42. $bname = 'Opera';
  43. $ub = "Opera";
  44. }
  45. elseif(preg_match('/Netscape/i',$u_agent))
  46. {
  47. $bname = 'Netscape';
  48. $ub = "Netscape";
  49. }
  50. // finally get the correct version number
  51. $known = array('Version', $ub, 'other');
  52. $pattern = '#(?<browser>' . join('|', $known) .
  53. ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  54. if (!preg_match_all($pattern, $u_agent, $matches)) {
  55. // we have no matching number just continue
  56. }
  57. // see how many we have
  58. $i = count($matches['browser']);
  59. if ($i != 1) {
  60. //we will have two since we are not using 'other' argument yet
  61. //see if version is before or after the name
  62. if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
  63. $version= $matches['version'][0];
  64. }
  65. else {
  66. $version= $matches['version'][1];
  67. }
  68. }
  69. else {
  70. $version= $matches['version'][0];
  71. }
  72. // check if we have a number
  73. if ($version==null || $version=="") {$version="?";}
  74. return array(
  75. 'userAgent' => $u_agent,
  76. 'name' => $bname,
  77. 'version' => $version,
  78. 'platform' => $platform,
  79. 'pattern' => $pattern
  80. );
  81. }
  82. // now try it
  83. $ua=getBrowser();
  84. $yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports: <br >" . $ua['userAgent'];
  85. print_r("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" />");
  86. print_r("<div id=\"wrap\">");
  87. print_r("<b><center><h2>Browser Check</h2><p><h4>This is a browser compatability check for accessing the secure portal for the GLI Gas Transfer Project.</h4></p>");
  88. #print_r($yourbrowser);
  89. #CHROME - all platforms (and generally versions) is okay)
  90. if (preg_match('/Chrom/',$ua['name']))
  91. {
  92. print_r("<p>Your browser is Google Chrome, Version ".$ua['version']." on ".$ua['platform']." - everything should work okay.</p><p><img src=\"/images/thumbsup.gif\"</p>");
  93. }
  94. elseif (preg_match('/Fire/',$ua['name']))
  95. {
  96. if ($ua['version'] < 3)
  97. {
  98. print_r("<p>Your browser is Mozilla Firefox, Version ".$ua['version']." on ".$ua['platform']." - this version is out of date, please upgrade by going to <a href=\"www.firefox.com\" target=\"_blank\">http://www.firefox.com</a>.</p></p><img src=\"/images/thumbsdown.gif\"</p>");
  99. }
  100. else
  101. {
  102. print_r("<p>Your browser is Mozilla Firefox, Version ".$ua['version']." on ".$ua['platform']." - everything should work okay.</p><p><img src=\"/images/thumbsup.gif\"</p>");
  103. }
  104. }
  105. elseif (preg_match('/Safari/',$ua['name'])) # Safari
  106. {
  107. print_r("<p>Your browser is Apple Safari, Version ".$ua['version']." on ".$ua['platform'].". Unfortunately this browser does not properly support the security features used for the GLI site. Can you please install Google Chrome (MacOS 10.6 or later) - <a href=\"http://www.google.com/intl/en/chrome/browser/\ target=\"_blank\">http://www.google.com/intl/en/chrome/browser/</a> or Mozilla Firefox - <a href=\"www.firefox.com\">http://www.firefox.com</a>.</p><p><img src=\"/images/thumbsdown.gif\"</p>");
  108. }
  109. elseif (preg_match('/Explorer/',$ua['name'])) #IE
  110. {
  111. if ($ua['version'] < 10)
  112. {
  113. print_r("<p>Your browser is Microsoft Internet Explorer, Version ".$ua['version']." on ".$ua['platform'].". Unfortunately this browser does not properly support the security features used for the GLI site. Can you please upgrade to Internet Explorer 10 (only if you are on Windows 7 above), or alternately please install Google Chrome - <a href=\"http://www.google.com/intl/en/chrome/browser/\ target=\"_blank\">http://www.google.com/intl/en/chrome/browser/</a> or Mozilla Firefox - <a href=\"www.firefox.com\">http://www.firefox.com</a>.</p><p><img src=\"/images/thumbsdown.gif\"</p>");
  114. }
  115. else
  116. {
  117. print_r("<p>Your browser is Microsoft Internet Explorer, Version ".$ua['version']." on ".$ua['platform']." - everything should work okay.</p><p><img src=\"/images/thumbsup.gif\"</p>");
  118. }
  119. }
  120. elseif (preg_match('/Opera/',$ua['name'])) #Opera
  121. {
  122. print_r("<p>Your browser is Opera, Version ".$ua['version']." on ".$ua['platform']." - everything should work okay (or if not, please upgrade to the latest version).</p><p><img src=\"/images/thumbsup.gif\"</p>");
  123. }
  124. else
  125. {
  126. print_r("<p>Your browser is ".$us['name'].", Version ".$ua['version']." on ".$ua['platform'].". This browser may not properly support the security features used for the GLI site. Can you please install Google Chrome - <a href=\"http://www.google.com/intl/en/chrome/browser/\ target=\"_blank\">http://www.google.com/intl/en/chrome/browser/</a> or Mozilla Firefox - <a href=\"www.firefox.com\">http://www.firefox.com</a>.</p><p><img src=\"/images/thumbsdown.gif\"</p>");
  127. }
  128. ?>