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
Share on other sites

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?

Link to comment
Share on other sites

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.