home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomePHP CookbookSearch this book

8.8. Detecting Different Browsers

8.8.3. Discussion

The get_browser( ) function examines the environment variable $_ENV['HTTP_USER_AGENT'] (set by the web server) and compares it to browsers listed in an external browser capability file. Due to licensing issues, PHP isn't distributed with a browser capability file. The "Obtaining PHP" section of the PHP FAQ (http://www.php.net/faq.obtaining) lists http://www.cyscape.com/asp/browscap/ and http://www.amrein. com/apps/page.asp?Q=InowDownload as sources for a browser capabilities file, and there is also one at http://asp.net.do/browscap.zip.

Once you download a browser capability file, you need to tell PHP where to find it by setting the browscap configuration directive to the pathname of the file. If you use PHP as a CGI, set the directive in the php.ini file:


If you use Apache, you need to set the directive in your Apache configuration file:

php_value browscap "/usr/local/lib/browscap.txt"

Many of the capabilities get_browser( ) finds are shown in Table 8-1. For user-configurable capabilities such as javascript or cookies though, get_browser( ) just tells you if the browser can support those functions. It doesn't tell you if the user has disabled the functions. If JavaScript is turned off in a JavaScript-capable browser or a user refuses to accept cookies when the browser prompts him, get_browser( ) still indicates that the browser supports those functions.

Table 8-1. Browser capability object properties




Operating system the browser is running on (e.g., Windows, Macintosh, UNIX, Win32, Linux, MacPPC)


Full browser version (e.g., 5.0, 3.5, 6.0b2)


Major browser version (e.g., 5, 3, 6)


Minor browser version (e.g., 0, 5, 02)


1 if the browser supports frames


1 if the browser supports tables


1 if the browser supports cookies


1 if the browser supports background sounds with <embed> or <bgsound>


1 if the browser supports VBScript


1 if the browser supports JavaScript


1 if the browser can run Java applets


1 if the browser can run ActiveX controls

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.