Could anyone tell me the best way to detect a browser using php? IE 6 and 7 are terrible when it comes to achieving full browser compatibility with CSS so my site isn\'t going t
The best way to detect the user's browser with PHP is to not check the user's browser with PHP.
You've mentioned that IE lt 8 sucks for CSS (and that is something every web dev can agree on), the best way to tell the user that their browser is too old is with a conditional comment in the HTML:
...
...
The code I've written shows two things you can do: first it shows you can set an IE only stylesheet, and secondly it shows you can set IE only chunks of HTML.
I see no reason you can't allow your IE users to use your wobsite, if it doesn't work, just let them know that it's their own fault for using a crummy browser.
This will also allow you to set a cookie for subsequent PHP calls: