I’ve posted about using JavaScript to detect specific browsers, but that script seems to have its limitations.  I’ve become infinitely more comfortable with PHP in recent years and find that the following is an acceptable option for detecting a browser.  Better yet, you can write code that will change depending on your visitor’s browser.  In this case, I use it to switch CSS files.  Here is the code:

<? // check for UA, convert UA string to lower case
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';

// Check browser and select CSS file
if (stristr($navigator_user_agent, "msie 6"))
echo '<link href="css/alternate.css" rel="stylesheet" type="text/css" />';

echo "<link href='css/style.css' rel='stylesheet' type='text/css' />";

If all went well you should now have a script that selects an alternate CSS file for your IE6 visitors. You can use else-if statements if you would like to add more contingencies. Another upside to this is if you’re using non-valid CSS (like *html for IE) you can shuffle it all away in another file that the W3C validator will never see. Devious!

Make sure you find your user agent string! Some of these are similar and will contain the names of other browsers, so be specific when you use a keyword to search the UA string.