I’m trying to avoid tons of PHP code by specifying that a remote stylesheet, containing CSS animation, should be loaded if the HTTP_USER_AGENT string corresponds to [browser version x] or later. For example, knowing that CSS animations are supported in Chrome 19 and newer, the code would detect if Chrome’s version is greater than 19, and load the appropriate stylesheet.
Is this feasible at all using PHP?
I’m trying to avoid tons of PHP code by specifying that a remote stylesheet,
Share
If you must use PHP for this, then there is a built-in function
get_browser()that does what you want.However… If you use
get_browser(), be aware that it is a bad solution to your problem.In order to user this function, you must have an up-to-date
browsecap.inifile, which is basically a text file that defines the capabilities of every browser and every version ever released.The downsides of this are obvious:
For all these reasons, I strongly recommend not using
get_browser(), or indeed any PHP-based or server-side solution.Instead, as others have said, you should investigate using the Modernizr library. This is a Javascript library that you install on your site that does feature detection in the browser. It will never be out of date, because it looks specifically at whether the features are supported, so it doesn’t care what the actual browser is.