note 119332 added to function.get-browser

From: Date: Sat, 14 May 2016 13:52:42 +0000
Subject: note 119332 added to function.get-browser
Groups: php.notes 
Request: Send a blank email to php-notes+get-205485@lists.php.net to get a copy of this message
If you ONLY need a very fast and simple function to detect the browser name (update to May 2016): <?php 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'; } // Usage: echo get_browser_name($_SERVER['HTTP_USER_AGENT']); ?> This function also resolves the trouble with Edge (that contains in the user agent the string "Safari" and "Chrome"), with Chrome (contains the string "Safari") and IE11 (that do not contains 'MSIE' like all other IE versions). Note that "strpos" is the fastest function to check a string (far better than "preg_match") and Opera + Edge + Chrome + Safari + Firefox + Internet Explorer are the most used browsers today (over 97%). ---- Server IP: 72.52.91.14 Probable Submitter: 79.31.184.5 ---- Manual Page -- http://php.net/manual/en/function.get-browser.php Edit -- https://master.php.net/note/edit/119332 Del: integrated -- https://master.php.net/note/delete/119332/integrated Del: useless -- https://master.php.net/note/delete/119332/useless Del: bad code -- https://master.php.net/note/delete/119332/bad+code Del: spam -- https://master.php.net/note/delete/119332/spam Del: non-english -- https://master.php.net/note/delete/119332/non-english Del: in docs -- https://master.php.net/note/delete/119332/in+docs Del: other reasons-- https://master.php.net/note/delete/119332 Reject -- https://master.php.net/note/reject/119332 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205485) next »