Get browser info quick function

There are more than one way to get the browsers information with PHP, so to make it simple, I have created this function that will check if the ini configuration is set to get the browser info, and if is not, then it will parse the $_SERVER variable to get the correct browser information.

function getBrowserInfo(){
$isBrowserCapSet = ini_get(‘browscap’);
$browser = ”;
if(strlen($isBrowserCapSet) > 0){
$browserInfoAsArray = get_browser(null,true);
return $browserInfoAsArray[‘browser’];
else {
$browserInfoAsArray = explode(‘ ‘,$_SERVER[‘HTTP_USER_AGENT’]);
if(isset($browserInfoAsArray[9]) && preg_match(‘/[a-zA-z]+/’,$browserInfoAsArray[9])>0){
$browserInfoAndVersion = explode(‘/’,$browserInfoAsArray[9]);
return $browserInfoAndVersion[0];
else if(isset($browserInfoAsArray[2])){
return $browserInfoAsArray[2];

P.S. This is not tested on all browsers.


About mcloide

Making things simpler, just check: View all posts by mcloide

2 responses to “Get browser info quick function

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: