Display Users Browsers Here is a small function to detect a users browser, and display a browser icon, if you have any. If you don't have any icons, or just don't want to use the feature, you can of course turn it off. Source Code: PHP: <?php function defineUserAgent($browser, $icon = true) { $browserIcons = array( 'Mozilla Firefox' => './firefox.png', // Mozilla Firefox Icon Location 'Internet Explorer' => './explorer.png', // Internet Explorer Icon location 'Opera' => './opera.png', // Opera Icon Locations 'Netscape' => './netscape.png' // Netscape Icon Location ); $browserIndex = array( 'Mozilla Firefox' => '/(firebird|firefox|gecko)/i', 'Opera' => '/opera/i', 'Netscape' => '/(netscape|mozilla)/i', 'Safari' => '/safari/i', 'Internet Explorer' => '/\msie/i', 'SearchBot' => '/(nuhk|googlebot|yammybot|openbot|slurp/cat|msnbot|ia_archiver)/i', 'OmniWeb' => '/omniweb/i', 'Flock' => '/flock/i', 'Links' => '/links/i', 'cURL' => '/curl/i', 'Galeon' => '/galeon/i', 'Epiphany' => '/epiphany/i', 'Lynx' => '/lynx/i', 'Wget' => '/wget/i', 'Phoenix' => '/phoenix/i', 'iCab' => '/icab/i', 'Camino' => '/camino/i', 'SeaMonkey' => '/seamonkey/i', 'Konqueror' => '/konqueror/i', 'Chimera' => '/chimera/i', 'MyIE' => '/myie/i' ); foreach($browserIndex as $browserName => $pattern) { if(preg_match($pattern, $browser)) { $browserIcon = ''; if ($browserIcons[$browserName]) { $browserIcon = ($icon) ? '<img src="' . $browserIcons[$browserName] . '" border="0"> ' : $browserIcon; } return $browserIcon . $browserName; } } } $userAgent = $_SERVER['HTTP_USER_AGENT']; $browser_with_icon = defineUserAgent($userAgent); // Browser name with a icon $browser_without_icon = defineUserAgent($userAgent, false); // Browser name without a icon echo 'You are running <b>' . $browser_with_icon . '</b><br /><br />'; echo 'You are running <b>' . $browser_without_icon . '</b>'; ?> Hope this helps you all.
Wow, nice post. Couldn't you also use call letters to find out if they are using a certain browser, then do something different.