Jump to content

[SOLVED] getting JUST the browser , IE,Firefoxxx,OPERA etc.


Recommended Posts

Hi guys, im having troubles just getting the BROWSER and nothing else.

 

Ive tried:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
$browser = explode(" ",$_SERVER['HTTP_USER_AGENT']);
echo $browser[0];

 

This returns:

Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.13) Gecko/2009080317 Fedora/3.0.13-1.fc10 Firefox/3.0.13

Mozilla/5.0

 

However if its internet explorer i get useless info.

 

Is there a better way to get this data?

 

basically its for visitors stats:

So a fucntion that gives me a bunch of vars like $browser $jsenabled $screensize $os  etc would be great.

 

cant find what i want anywhere :(

 

Thanks

G

The browser is contained within the user agent, you are extracting the wrong part of the string.

Internet Explorer 7

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; IEMB3; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET LR 2.0.50727; ZangoToolbar 4.8.3)

 

Firefox 3.0.13

Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.13) Gecko/2009080317 Fedora/3.0.13-1.fc10 Firefox/3.0.13

 

http://www.user-agents.org/

You should check for a value within the user agent rather than extract it as all user agents are formatted differently and map it to a list of browsers i.e. array of browsers

Just find the parts of the user agent that identify what the browser is and then add to an array. Here's a start:

<?php
function isBrowser($userAgent) {
$browsers = array('msie' 	=> 'internet explorer',
				  'firefox'	=> 'mozilla firefox',
				  'avant'	=> 'avant browser');
foreach($browsers as $ident => $browser) {
	if(stristr($userAgent, $ident)) {
		return $browser;
	}
}
return false;
}


// usage
if($x = isBrowser($_SERVER['HTTP_USER_AGENT'])) {
print "Your browser is: ".$x;
}
else {
print "Unknown web browser";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.