Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get browser info in php

function get_agent_info() {
  $u_agent = $_SERVER['HTTP_USER_AGENT'];
  $temp = strtolower($_SERVER['HTTP_USER_AGENT']);

  $bname    = 'Unknown';
  $platform = 'Unknown';
  $version  = "";

  // Get the platform
  if (preg_match('/linux/i', $temp)) {
    $platform = 'linux';
  }
  elseif (preg_match('/macintosh|mac os x/i', $temp)) {
    $platform = 'mac';
  }
  elseif (preg_match('/windows|win32/i', $temp)) {
    $platform = 'windows';
  }

  // Get the name of the useragent
  if(preg_match('/msie/i',$temp) && !preg_match('/opera/i',$temp)) {
    $bname = 'Internet Explorer';
    $ub = "msie";
  }
  elseif(preg_match('/firefox/i',$temp)) {
    $bname = 'Mozilla Firefox';
    $ub = "firefox";
  }
  elseif(preg_match('/chrome/i',$temp)) {
    $bname = 'Google Chrome';
    $ub = "chrome";
  }
  elseif(preg_match('/safari/i',$temp)) {
    $bname = 'Apple Safari';
    $ub = "safari";
  }
  elseif(preg_match('/opera/i',$temp)) {
    $bname = 'Opera';
    $ub = "opera";
  }
  elseif(preg_match('/netscape/i',$temp)) {
    $bname = 'Netscape';
    $ub = "netscape";
  }

  $known = array('version', $ub, 'other');
  $pattern = '#(?<browser>' . join('|', $known) .')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  preg_match_all($pattern, $temp, $matches);

  $i = count($matches['browser']);
  if ($i != 1) {
    if (strripos($temp,"version") < strripos($temp,$ub)) {
      $version = $matches['version'][0];
    }
    else {
      $version = $matches['version'][1];
    }
  }
  else {
    $version = $matches['version'][0];
  }

  if ($version == null || $version == "") {
    $version = "?";
  }

  return array(
    'userAgent' 	=> $u_agent,
    'browser'      	=> $bname,
    'version'   	=> $version,
    'platform' 		=> $platform,
  );
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel request validate audio 
Php :: In Connection.php line 664:SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema 
Php :: laravel make model with migration and controller 
Php :: php mysql count rows 
Php :: laravel seed specific file 
Php :: php get only numbers from string 
Php :: validate year laravel 
Php :: string to uppercase laravel 
Php :: php change file extension 
Php :: codeigniter get where 
Php :: set charset of response php 
Php :: time to load php page 
Php :: node dockerfile 
Php :: for loop php 
Php :: laravel get last record 
Php :: wordpress PHPMailer config 
Php :: How to Get the last element of an array in PHP – end() 
Php :: convert base64 string to pdf in php 
Php :: php remove quotes from string 
Php :: 419 unknown status 
Php :: get post order by meta value int 
Php :: geoip php sample 
Php :: group by laravel 
Php :: laravel check if get is empty 
Php :: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes 
Php :: whereyear laravel 
Php :: laravel vendor publish all files 
Php :: eloquent using last() 
Php :: west african timezone in php 
Php :: laravel get query output 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =