I found some php code for detecting if a user is on Chrome:
<?php $b_name = get_browser_name($_SERVER['HTTP_USER_AGENT']); function get_browser_name($user_agent){ if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera'; elseif (strpos($user_agent, 'Edge')) return 'Edge'; elseif (strpos($user_agent, 'Chrome')) return 'Chrome'; elseif (strpos($user_agent, 'Safari')) return 'Safari'; elseif (strpos($user_agent, 'Firefox')) return 'Firefox'; elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer'; return 'Other'; } echo "You browser is <b>$b_name</b> ."; ?> It seems to work when I test it, but when deployed it seems to be giving off a lot of false negatives where the user is on Chrome but it shows Mozilla.
Any idea where it might be going wrong? Or is this good code?
Mozilla compatible Xalso Chrome may include Safari in there as well. Could useMobileDetect(I know it's mostly about mobile browsers but it also has user agent type detection as a bonus)