lynxus Posted August 26, 2009 Share Posted August 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/171954-solved-getting-just-the-browser-iefirefoxxxopera-etc/ Share on other sites More sharing options...
JonnoTheDev Posted August 26, 2009 Share Posted August 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/171954-solved-getting-just-the-browser-iefirefoxxxopera-etc/#findComment-906681 Share on other sites More sharing options...
lynxus Posted August 26, 2009 Author Share Posted August 26, 2009 Humm, So theres no easy way then? I need to download the database and compare against that? Quote Link to comment https://forums.phpfreaks.com/topic/171954-solved-getting-just-the-browser-iefirefoxxxopera-etc/#findComment-906684 Share on other sites More sharing options...
JonnoTheDev Posted August 26, 2009 Share Posted August 26, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171954-solved-getting-just-the-browser-iefirefoxxxopera-etc/#findComment-906688 Share on other sites More sharing options...
lynxus Posted August 26, 2009 Author Share Posted August 26, 2009 AHHH i seee. Thank you for your help!! Graham Quote Link to comment https://forums.phpfreaks.com/topic/171954-solved-getting-just-the-browser-iefirefoxxxopera-etc/#findComment-906693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.