Get browser capabilities information

The object returned by get_browser() can be used to determine a browser’s capabilities.The get_browser() function examines the environment variable (set by the web server) and compares it to browsers listed in an external browser capability file. We can download php_browscap.ini file from any site and 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

$browser = get_browser();
if ($browser->frames) {
    // print out a frame-based layout
} elseif ($browser->tables) {
    // print out a table-based layout
} else {
    // print out a boring layout

Setting browscap in php.ini


Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.