Jump to content

- - - - -

Browser Detection?

  • Please log in to reply
3 replies to this topic

#1 5imp7y


    Hakker addict

  • Binrev Financier
  • 507 posts
  • Gender:Male
  • Country:
  • Location:PA again....

Posted 14 February 2013 - 12:34 PM

Once again i get put in some easy and tiresome web development class here at my university. I have to make a web page.... 5 pages, galary, submit form, mailto and href...blah blah blah. I really want to wow the teacher, and somthing that i tought would  be nice would be the option for mobile access and a secure line (https). I have the php server side down, but i have no clue how to impliment browser detection...? Im faily sure it is done through java. Anyone have any good lituratue for me? Hopfully somthing a little more idiot proff than this >> http://jibbering.com...t-browser/#bdFD


Thanks. Btw, my knowledge in java is trivial on a good day. C++ im intermediate and html im an advance user. Thanks everyone.


Binrev lives forever.

#2 systems_glitch


    Dangerous free thinker

  • Moderating Team
  • 1,782 posts
  • Gender:Male

Posted 14 February 2013 - 03:37 PM

You may have more luck doing it with JavaScript. Everyone seems to be using jQuery nowadays:




Recommended practice is, include jQuery from Google since most browsers have already cached it. Google supports/encourages this. Of course, a JS source include from a non-HTTPS source makes your HTTPS-served page less secure.


If you want a canned UI to work with, take a look at Twitter Bootstrap. That may be considered cheating for your particular assignment, though!

#3 Bit Viper

Bit Viper

    SCRiPT KiDDie

  • Binrev Financier
  • 28 posts
  • Gender:Male
  • Country:

Posted 14 February 2013 - 05:45 PM

User agent string is probably the quickest way out the door. No add-ons or plugins or runtime environments. Just capture User-Agent using your server- or client-side scripting language of choice, and roll with it. Easy. :shuriken:

#4 TheFunk


    SUP3R 31337

  • Members
  • 192 posts
  • Gender:Male
  • Country:

Posted 14 February 2013 - 11:32 PM

Howdy. Bitviper is correct. I half-stole this when I wrote it for my site , but if you'd like to see an example of how the http user-agent string can be used, here you go!


        $address = ($_SERVER['REMOTE_ADDR']);
        $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
        echo '<span class="phptext">Your external IP address is </span>';
        echo '<span class="phptext">', $address, '</span>';
        echo '<br>';
        //The OS detection script used here was taken from geekpedia.com
        //It is sightly modified for my purposes.
        //The original code was by Andrew Pociu, and then modified by Kevin F.
        /*It can be found here:
         * http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html
        $osList = array
'Windows 8' => 'windows nt 6.2',           
'Windows 7' => 'windows nt 6.1',
'Windows Vista' => 'windows nt 6.0',
'Windows Server 2003' => 'windows nt 5.2',
'Windows XP' => 'windows nt 5.1',
'Windows 2000 sp1' => 'windows nt 5.01',
'Windows 2000' => 'windows nt 5.0',
'Windows NT 4.0' => 'windows nt 4.0',
'Windows Me' => 'win 9x 4.9',
'Windows 98' => 'windows 98',
'Windows 95' => 'windows 95',
'Windows CE' => 'windows ce',
'Windows (version unknown)' => 'windows',
'OpenBSD' => 'openbsd',
'SunOS' => 'sunos',
'Ubuntu (or a Ubuntu derivative)' => 'ubuntu',
'Android OS' => 'android',
'Apple iOS' => 'iphone',
'Linux' => '(linux)|(x11)',
'Mac OSX Beta (Kodiak)' => 'mac os x beta',
'Mac OSX Cheetah' => 'mac os x 10.0',
'Mac OSX Puma' => 'mac os x 10.1',
'Mac OSX Jaguar' => 'mac os x 10.2',
'Mac OSX Panther' => 'mac os x 10.3',
'Mac OSX Tiger' => 'mac os x 10.4',
'Mac OSX Leopard' => 'mac os x 10.5',
'Mac OSX Snow Leopard' => 'mac os x 10.6',
'Mac OSX Lion' => 'mac os x 10.7',
'Mac OSX (version unknown)' => 'mac os x',
'Mac OS (classic)' => '(mac_powerpc)|(macintosh)',
'QNX' => 'QNX',
'BeOS' => 'beos',
'OS2' => 'os/2',
'SearchBot'=>'(nuhk)|(googlebot)|(yammybot)|(openbot)|(slurp)|(msnbot)|(ask jeeves/teoma)|(ia_archiver)'

foreach($osList as $os=>$match)
        if (preg_match('/' . $match . '/i', $useragent))
        $os = "Not automatically detected.<br>$useragent";

echo '<span class="phptext">Your Operating System is </span>';
echo <<<HEYHO
<span class="phptext">$os</span>;
echo '<br>';

//I liked that code so much. I decided to make a browser checker from it.
        $browlist = array

'Internet Explorer. Laaaame.' => 'msie', 
'Mozilla Firefox. Good on ya!' => 'firefox',
'Google Chrome. Meh.' => 'chrome',
'Opera. Is your name Jake?' => 'opera',

foreach($browlist as $brow=>$check)
    if (preg_match('/' . $check . '/i', $useragent))
            $brow = "a mystery! Gasp!<br>$useragent";

echo'<span class="phptext">Your browser is </span>';
echo <<<LETSGO
<span class="phptext">$brow</span>


If you'd like to see the end result check out www.thefunkspace.com, but be warned, I'm terribad at web design, so it looks horrendous. Also I don't have any good content on the site yet whatsoever. It's going to be remade with wordpress or drupal or something like that, and then it'll get some content.

  • tekio likes this

BinRev is hosted by the great people at Lunarpages!