Jump to content

Finding out what browser a user users


Howlin1

Recommended Posts

Hello I am trying to have an index page saying

"Your browser is XYZ and you are using version 123"

 

However I seem to be only able to do it if I stick in a lot of if else statements.

e.g

<?php
require_once('Browser.php');
$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
echo 'You have FireFox version 2 or greater';
}
?>

I want it so I only need to do something like

<?php
require_once('Browser.php');
$browser = new Browser();
echo 'You are using' . $browser_name . 'version' . $broswer_version;
?>

I have been trying for a while to get it to work, but I can't seem to be able to do it.

Is there any esay way of doing it or will I need to do it like in my example?

Link to comment
https://forums.phpfreaks.com/topic/223228-finding-out-what-browser-a-user-users/
Share on other sites

..and you could also use the excellent browser capabilities library: http://browsers.garykeith.com/downloads.asp

 

EDIT: should note, benefit in this is that the browser specs are updated automatically for you and so you don't have to worry about maintaining the class.

I want to try stay away from javascript as much as I can because if a user has javascript disabled then the script isn't much use.

 

I changed the Browser.php file from

return "<strong>Browser Name:</strong>{$this->getBrowser()}<br/>\n" .
		       "<strong>Browser Version:</strong>{$this->getVersion()}<br/>\n" .
		       "<strong>Browser User Agent String:</strong>{$this->getUserAgent()}<br/>\n" .
		       "<strong>Platform:</strong>{$this->getPlatform()}<br/>";
	}

 

to

return "You are using <b> {$this->getBrowser()} </b> version <b> {$this->getVersion()}</b>";

and the index file to

<?php
require_once('Browser.php');
$browser = new Browser();
echo $browser;
?>

so it now prints out

You are using Firefox version 3.6.13

 

That is all that I really need it to do.

Is there any disadvantages to doing that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.