Sign in to follow this  
Followers 0
epew23

Browser Detection?

4 posts in this topic

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/faq/notes/detect-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.

0

Share this post


Link to post
Share on other sites

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

 

http://api.jquery.com/jQuery.browser/

 

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!

0

Share this post


Link to post
Share on other sites

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:

0

Share this post


Link to post
Share on other sites

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!

 

<?php        $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))    {        break;    }    else    {        $os = "Not automatically detected.<br>$useragent";    }}echo '<span class="phptext">Your Operating System is </span>';echo <<<HEYHO<span class="phptext">$os</span>;HEYHO;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))        {            break;        }    else        {            $brow = "a mystery! Gasp!<br>$useragent";        }}echo'<span class="phptext">Your browser is </span>';echo <<<LETSGO<span class="phptext">$brow</span>LETSGO;   ?>

 

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.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0