Howlin1 Posted January 3, 2011 Share Posted January 3, 2011 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 More sharing options...
requinix Posted January 3, 2011 Share Posted January 3, 2011 Modify the Browser class to have what you want. Mind you, you'll still need the "a lot of if else statements", but it'll be behind-the-scenes. So no, you can't really escape from that. Link to comment https://forums.phpfreaks.com/topic/223228-finding-out-what-browser-a-user-users/#findComment-1154055 Share on other sites More sharing options...
JD* Posted January 3, 2011 Share Posted January 3, 2011 You could also use javascript to do this: http://www.w3schools.com/js/js_browser.asp Link to comment https://forums.phpfreaks.com/topic/223228-finding-out-what-browser-a-user-users/#findComment-1154057 Share on other sites More sharing options...
Anti-Moronic Posted January 3, 2011 Share Posted January 3, 2011 ..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. Link to comment https://forums.phpfreaks.com/topic/223228-finding-out-what-browser-a-user-users/#findComment-1154070 Share on other sites More sharing options...
Howlin1 Posted January 3, 2011 Author Share Posted January 3, 2011 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 https://forums.phpfreaks.com/topic/223228-finding-out-what-browser-a-user-users/#findComment-1154170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.