DekGenius.com
Previous Section  < Day Day Up >  Next Section

13.4 Browser-Specific Code

The get_browser( ) function gives you information about the characteristics and capabilities of a user's browser. It makes it easy to dynamically determine what kind of page to output based on what a browser can do, what kind of browser it is, or on what operating system it's running. Example 13-5 prints a message that depends on the operating system of the user's browser.

Example 13-5. Using get_browser( )
$browser = get_browser( );

if ($browser->platform =  = 'WinXP') {
    print 'You are using Windows XP.';
} elseif ($browser->platform =  = 'MacOSX') {
    print 'You are using Mac OS X.';
} else {
    print 'You are using a different operating system.';
}

The get_browser( ) function uses the $_SERVER['HTTP_USER_AGENT'] variable described in Table 6-1. Remember, that variable can be faked, but it is still useful in producing customized pages for the majority of your users. For get_browser( ) to work, you need to download a separate browser capabilities file and set the browscap configuration directive. The PHP Manual page about get_browser( ) (http://www.php.net/get_browser) provides up-to-date information on where to get a browser capabilities file.

    Previous Section  < Day Day Up >  Next Section