To support all browsers I created different stylesheets for IE5,6,7 & opera. You can then use conditional comments to detect current browser. This does not work for me because I use IE5 stand alone and cc checks registry. Opera does not work with cc either.
So I had to find another solution. I came up with php. I use this variable to detect browser: $_SERVER['HTTP_USER_AGENT'].
My question is: is the browser detection by php fully reliable? At least it works for me, tested it on Opera, IE5.01, IE6.0 & IE7!
PHP browser detection is normally reliable as most browsers pass a string to each web page with the name of the browser. However, you'll need to be careful with Opera (which sometimes pretends that it is Internet Explorer) and people who have installed some Norton tools which sometimes block or change the browser string. Other than that, there aren't any problems :)
Honestly, I wouldn't rely on the _SERVER user agent for your detection. There are several ways around this depending on how/what people are using to access your website. You can get a general idea, but I don't believe you can hit the nail on the head with every browser.
What if they telnet and spoof the user agent? What if they change it with their browser to mask as another browser?
In general - I dont think its PHP - its more of narrowing down a specific user agent as it is so easy to change this.
This does not work for me because I use IE5 stand alone and cc checks registry.
If you get the .bat and .vbs files from this tutorial on using ie7 as a standalone and revise them to use with ie5.* (change the value of the registry key it adjusts) then you can run standalone ie5.* with conditional comments just fine. (I do this on my work machine so I can have IE6, 7b2 and 5.5 for testing.)
If you want to create a diffrent style sheet for opera it's not going to work like that, becouse by default Opera identifies as Internet Explorer. Now theres a problem.
I would suggest to think of a diffrent way to get what you want with css, not create diffrent style sheets for diffrent browsers.
I'm not sure if the browser detection is right approach to you problem. Still remember it's not possible to develop website that will look 100% the same in any browser and any version of this browser. But for the most browsers if coded you pages correctly and took in consideration little differences they have you should be fine. I personally against browser hacks for general use there is always way around the problem.