In this tutorial we will learn How To Detect Visitors Browser Using PHP, for this we can use $_SERVER['HTTP_USER_AGENT'].
Table of Contents
PHP Code
PHP code is given below to find the browsers name.
<?php
if(strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
echo " Internet explorer";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) {
echo " Internet explorer";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) {
echo " Firefox";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {
echo " Chrome";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Oper Mini') !== FALSE) {
echo " Opera mini";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {
echo " Safari";
}
elseif(strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) {
echo " Opera";
}
else {
echo "something else";
}
?>