Thanks for this code snippet, just had a similar need where the differences between Chrome, FF and IE do't stack up, and a simple ccs coding doesn't do the job anymore, so a dedicated HTML page has had to be created for not only Browser, but display sizes so as to cover 4:3 16:9 ratio screens...
Anyway, using your example, I have developed the php to provide feedback for browser type, build and screen resolution.
Hope you find this adaptation of use, if anyone improves on it, welcome the improvements as only spent 1hr on this so haven't had the opportunity to specify all the options for the many browser types - so currently is only developed fully for Chrome, IE and FF
enjoy::
// Start of code //////////////////////////////////////////////
// Source http://stackoverflow.com/questions/6660649/mobile-or-desktop-browser-detection-and-redirect-to-respective-web-page
// Updated Added 14 0220
// need to identify different browsers so as to display correct Window/Div sizing!
$USER_AGENT = explode('/', $_SERVER ['HTTP_USER_AGENT']);
// print_r ($USER_AGENT);
/* Eliminate IE */
if (strpos($USER_AGENT[1], 'MSIE') !== false ){
// echo "Browser ::\t TEST";
}
$browserDetect = explode (" ",$USER_AGENT[2]);
//print_r ($browserDetect);
// Need to swop around the Keys so that the Browser is the first key in the array - makes things easier with detecting
$browserDetect = array_reverse ($browserDetect);
//print_r ($browserDetect);
/* Redirection */
switch ($browserDetect[0]) {
case 'Mozilla' :
echo "Browser ::\t Mozilla";
break;
case 'Chrome' :
echo "\nBrowser ::\t Chrome";
// build =
$browserBuild = explode (" ",$USER_AGENT[3]);
echo "\nBuild ::\t ".$browserBuild[0];
break;
case 'Firefox' :
echo "Browser ::\t Firefox";
// build =
echo "\nBuild ::\t ".$USER_AGENT[3];
break;
case 'Gecko' :
echo "Browser ::\t IE";
// build =
$browserBuild = explode (" ",$USER_AGENT[2]);
echo "\nBuild ::\t ".$browserBuild[2];
break;
case 'Opera' :
echo "Browser ::\t Opera";
break;
case 'Googlebot' :
echo "Browser ::\t Googlebot";
break;
case 'msnbot' :
echo "Browser ::\t msnbot";
break;
case 'Safari' :
echo "Browser ::\t Safari";
break;
default :
echo "Browser ::\t Unsure what browser your using?";
break;
};
// Added 14 0220 /// Source:: http://en.kioskea.net/faq/1251-php-detect-the-display-resolution
// Needed to set the Viewer Screen for FF and IE
if(!isset($_GET['r']))
{
echo "<script language=\"JavaScript\">
<!--
document.location=\"$PHP_SELF?r=1&width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else {
// Code to be displayed if resolutoin is detected
if(isset($_GET['width']) && isset($_GET['Height'])) {
echo "\nScreen size ::\t ".$_GET['width']."x".$_GET['Height'];
}
else {
// Resolution not detected
}
}
// End of code snippet /////////////////////////////////////////////////////////////////////////////