You should already know that you can use the $_SERVER['HTTP_USER_AGENT'] variable to see what web browser requested a page, but how can you tell whether that browser supports the HTML IFRAME element? Does that browser support CSS 2? What version number is it?
While you could glean a little more information by actually parsing the user agent, a much better solution is to let PHP do it for you! This is done using the get_browser() function, which, when given no parameters, parses the user agent from $_SERVER['HTTP_USER_AGENT']. Alternatively, you can pass it a particular user agent to work with. Either way, it returns an object that contains information about that particular web browser: what it's capable of, what version it is, and what platform it's running on.
The function works by looking up the user agent in its long list of browsers, and reading from there what that browser supports. You need to download this browser list yourself - the latest URLs are always kept in the PHP manual, but last time I checked it was http://www.garykeith.com/browsers/downloads.asp . Look in the manual for the get_browser() function, then search the page for "browscap.ini" - the name of the browser capabilities file. Download the file (at the time of writing, the link on the PHP site takes you to another site that has a PHP-specific browscap.ini file) and place it either in c:\Windows for Windows users or /etc for Unix users, then open up your php.ini file. In there, search for the line "[browscap]" and edit the next line to point to your new browscap.ini file. So, it might look like this:
browscap = c:/windows/browscap.ini
Save the file and restart your web server to have the new browscap file loaded. Now, onto the code! The easiest way to get started is just to dump out all the information so you get an idea what's on offer:
From that you can see I'm running IE6 on Windows XP with .NET installed, it supports CSS v2.0, as well as HTML frames and IFRAME elements. There are quite a few other things there, too - try it yourself for more.
Now, just dumping out information like that is no use to anyone - what you really want to do is get down to the nitty-gritty of actually using that information in a smart way. For example, we could use it to load a custom CSS file for the various browsers out there. Keep in mind that each browser usually has its own way of rendering CSS styles, so having different stylesheets for each browser makes a lot of sense!