Hello I have this code to detect the user browser, using if and else:
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
echo 'Internet explorer';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE)
echo 'Mozilla Firefox';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE)
echo 'Google Chrome';
else
echo 'Something else';
?>
Is there a way to do this using the switch statement?
I tried this, and it does not work, it just retuns default:
<?php
switch(strpos($_SERVER['HTTP_USER_AGENT'], $browser) !== FALSE) {
case $browser='MSIE':
echo 'Internet explorer...';
case $browser='Firefox':
echo 'Mozilla Firefox...';
case $browser='Chrome';
echo 'Google Chrome...';
default:
echo 'Something else...';
}
?>