DETECTING BROWSERS AND OPERATING SYSTEMS - Jul 4th, 2012
|
There are times when it's important to be able to serve up different code or messages based on either the OS or Browser being used.
There are more comprehensive solutions, but here's a simple function that you can use for that purpose.
The example can be pasted in the body of your page and is set up to test for the combination of Windows XP and Internet Explorer.
<?php function os_detection () {
if (isset ($_SERVER['HTTP_USER_AGENT'])) { if (strpos ($_SERVER['HTTP_USER_AGENT'], 'MSIE') && (strpos ($_SERVER['HTTP_USER_AGENT'], 'Windows NT 5.1') !== false) return true; if (strpos ($_SERVER['HTTP_USER_AGENT'], 'MSIE') && (strpos ($_SERVER['HTTP_USER_AGENT'], 'Windows XP' ) !== false) return true; }
return false; } ?> <?php if (os_detection()) : ?> We've determined that your computer is using a combination of Windows XP and the Internet Explorer browser.Sorry for the inconvenience, but to use this page with Windows XP, you'll need to use the another browser, like the free Firefox browser.If you need to, you can download the latest version from <a href="http://www.mozilla.org/en-US/firefox/new/">http://www.mozilla.org/en-US/firefox/new/</a>.Installation is automatic, you can leave multiple browsers on your system, and they won't interfere with using Internet Explorer at other times.Thanks,Photo Canvas Arts Webmaster <?PHP else: ?> Other Code... <?PHP endif ?>
By far not comprehensive, but here's a list of user Agent strings for some of the most common OS's and Browsers.
iPhone : iPhone Windows 3.11: Win16 Windows 95: Windows 95 and Win95 and Windows_95 Windows 98: Windows 98 and Win98 Windows 2000: Windows NT 5.0 and Windows 2000 Windows XP: Windows NT 5.1 and Windows XP Windows 2003: Windows NT 5.2 Windows Vista: Windows NT 6.0 and Windows Vista Windows 7: Windows NT 6.1 and Windows 7 Windows NT 4.0: Windows NT 4.0 and WinNT4.0 and WinNT and Windows NT Windows ME: Windows ME Open BSD: OpenBSD Sun OS: SunOS Linux: Linux and X11 Safari: Safari Macintosh: Mac_PowerPC and Macintosh QNX: QNX BeOS: BeOS OS/2: OS/2
___
Opera: Opera Mozilla Firefox: Firebird and Firefox Galeon: Galeon Mozilla: Gecko MyIE: MyIE Lynx: Lynx Netscape: Mozilla/4\.75 and Netscape6 and Mozilla/4\.08 and Mozilla/4\.5 and Mozilla/4\.6 and Mozilla/4\.79 Konqueror: Konqueror SearchBot: nuhk and Googlebot and Yammybot and Openbot and Slurp/cat and msnbot and ia_archiver Internet Explorer All: MSIE Internet Explorer 8: MSIE 8\.[0-9]+ Internet Explorer 7: MSIE 7\.[0-9]+ Internet Explorer 6: MSIE 6\.[0-9]+ Internet Explorer 5: MSIE 5\.[0-9]+ Internet Explorer 4: MSIE 4\.[0-9]+
There's also a get browser PHP function that can be used: http://php.net/manual/en/function.get-browser.php
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.