@Ekramul Hoque was on the right track but there are several flaws to his answer.
First of all, I would begin with Edge as Internet Explorer does not contain the term Edge in any of its UAs.
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== FALSE) {
echo '<link type="text/css" href="ms.css" />';
Then, continue to work backward as earlier versions of IE didn't use the Trident engine and therefore won't contain it in their UA.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) {
echo '<link type="text/css" href="ms.css" />';
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
echo '<link type="text/css" href="ms.css" />';
We need to target iOS browsers next so that the subsequent queries don't interfere with this one. All iOS browsers use webkit with the exception of Opera Mini, which does its rendering from a remote server instead of the device. This means that we can target the OS in the UA with iOS and exclude UAs that contain Opera.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iOS') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE {
echo '<link type="text/css" href="webkit.css" />';
Next, move on to Firefox browsers. While using Firefox for the search term will work, it will only identify Firefox browsers--not Firefox based browsers. Firefox contains Gecko in its UA as Gecko is the engine that it uses, and we can therefore target that. By using Gecko, we can identify all browsers that run on the Gecko engine (ie SeaMonkey). However, many browsers use the term like Gecko for compatibility reasons, so we must be sure to match Gecko and not like Gecko.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') && !strpos($_SERVER['HTTP_USER_AGENT'], 'like Gecko') !== FALSE) {
echo '<link type="text/css" href="moz.css" />';
Moving on we'll identify Opera browsers. Opera used the Presto engine to the end of v12. Starting with v15, they began using the Blink engine like Chrome. v12 and earlier contained two unique words in the UA that v15+ doesn't have--Opera and Presto. You can target either of them as they were always present together. For v15, Opera began using OPR in the UA.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Presto') !== FALSE) {
echo '<link type="text/css" href="o.css" />';
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'OPR') !== FALSE) {
echo '<link type="text/css" href="normal.css" />';
Next up is Safari. Safari uses AppleWebKit as its rendering engine, but we can't just target that because Chrome also includes both AppleWebKit and Safari in its UA for compatibility reasons. Therefore, we need to search for AppleWebKit and not Chrome.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {
echo '<link type="text/css" href="webkit.css" />';
Finally, we get to Chrome. Chrome used AppleWebKit until v27. With the v28 release, they switched over to the Blink engine. We could target both engines but it would require a lot of code. Being that Chrome is almost to v70 now, we'll just search for Chrome as it's highly unlikely anyone is still running a webkit version of Chrome.
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE {
echo '<link type="text/css" href="normal.css" />';
And last but not least, your fallback/else.
} else {
echo '<link type="text/css" href="normal.css" />';
}
Now, I used css files referring to the vendor prefix to target here. Feel free to tweak this as needed to have it do what you need it to do. I hope this helped.