Trying to detect a user's browser with PHP only, is $_SERVER['HTTP_USER_AGENT'] a reliable way? Should I instead opt for the get_browser function? which one do you find brings more precise results?
If this method is pragmatic, is it ill advised to use it for outputting pertinent CSS links, for example:
if(stripos($_SERVER['HTTP_USER_AGENT'],"mozilla")!==false) echo '<link type="text/css" href="mozilla.css" />';
I noticed this question, however I wanted to clarify whether this is good for CSS-oriented detection.
UPDATE: something really suspicious: I tried echo $_SERVER['HTTP_USER_AGENT'];
on IE 7 and this is what it output:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Safari gave something weird with "mozilla" in it too. What gives?
Check this code , I've found this is useful. Don't check Mozilla because most browser use this as user agent string
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) echo 'Internet explorer'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) //For Supporting IE 11 echo 'Internet explorer'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) echo 'Mozilla Firefox'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) echo 'Google Chrome'; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== FALSE) echo "Opera Mini"; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) echo "Opera"; elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) echo "Safari"; else echo 'Something else';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With