note 115972 deleted from function.get-browser by cmb
| From: | cmb@php.net | Date: | Sun, 23 Feb 2020 08:53:11 +0000 |
| Subject: | note 115972 deleted from function.get-browser by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214185@lists.php.net to get a copy of this message | ||
Note Submitter: Billscott
----
After a great deal of research in to how to detect a users browser using php.I found out that the
following code below works best so i feel like sharing.
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/safari/i', $user_agent)) {
echo "safari";
}else if (preg_match('/Mozilla/i', $user_agent)) {
echo "Mozilla";
}else if (preg_match('/chrome/i', $user_agent)) {
echo "chrome";
}else{
echo "You are not using any of the major browsers";
}
?>