UserAgentHelper.php 612 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace common\helpers;
  3. class UserAgentHelper
  4. {
  5. /**
  6. * @param null|string $userAgent
  7. * @return bool
  8. */
  9. public static function isIE($userAgent = null)
  10. {
  11. if ($userAgent === null) {
  12. $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : null;
  13. }
  14. if ($userAgent == null) {
  15. return false;
  16. }
  17. if (strpos($userAgent, 'MSIE ') > 0 || strpos($userAgent, 'Trident/') > 0 || strpos($userAgent, 'Edge/') > 0) {
  18. return true;
  19. } else {
  20. return false;
  21. }
  22. }
  23. }