Source Code:
(back to article)
<?php // in reality you would do $user_agent = $_SERVER['HTTP_USER_AGENT']; $user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"; $browser = "Unknown browser"; if (preg_match('/MSIE/i', $user_agent)) { $browser = 'Internet Explorer'; } elseif (preg_match('/Firefox/i', $user_agent)) { $browser = 'Mozilla Firefox'; } elseif (preg_match('/Chrome/i', $user_agent)) { $browser = 'Google Chrome'; } elseif (preg_match('/Safari/i', $user_agent)) { $browser = 'Apple Safari'; } elseif (preg_match('/Opera/i', $user_agent)) { $browser = 'Opera'; } echo "Your browser is: " . $browser; ?>
Result:
Report an issue