How to perform browser discovery - IE (version) in PHP

I found this code to detect browser through php:

<?php
$msie = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false;
$firefox = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false;
$safari = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false;
$chrome = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false;
?>

<?php
//Firefox
if ($firefox) {
echo 'you are using Firefox!';
echo '<br />';
}

// Safari or Chrome. Both use the same engine - webkit
if ($safari || $chrome) { 
echo 'you are using a webkit powered browser';
echo '<br />';
}

// IE
if ($msie) {
echo '<br>you are using Internet Explorer<br>';
echo '<br />';
}?>

Source

But the code does not include possible versions of IE. Something like that:

// IE7
if ($msie7) {
echo '<br>you are using Internet Explorer 7<br>';
echo '<br />';
}

Can someone help me? Improved code is required, including IE support versions.

+3
source share
3 answers

Try the following:

<?php
    $ie6 = (ereg("MSIE 6", $_SERVER["HTTP_USER_AGENT"])) ? true : false;
    $ie7 = (ereg("MSIE 7", $_SERVER["HTTP_USER_AGENT"])) ? true : false;
    $ie8 = (ereg("MSIE 8", $_SERVER["HTTP_USER_AGENT"])) ? true : false;

    if ($ie6 || $ie7 || $ie8) {
        // Do fallback stuff that old browsers can do here
        echo "You are using IE";
    } else {
        // Do stuff that real browsers can handle here
    }
?>
+6
source

This PHP function works fine. But I don’t know how to make PHP different between different versions of "MSIE"

    <?php 
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){
        header( 'Location: http://www.domain.com' ) ;
    }
?>

Thank you very much

+1
source

PHP , . , . $_SERVER['HTTP_USER_AGENT'] - , , .

- CSS JS, -, <!--[if IE 8]><![endif]--> shim, , -, IE11 ...

JS , , JS, , .

, , , $_SERVER['HTTP_USER_AGENT'], , .

- CSS:

.someClass{
    -webkit-box-shadow: 0 0 5px black;
    -moz-box-shadow:    0 0 5px black;
    box-shadow:         0 0 5px black;

    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    -o-transform: rotate(45deg);
    transform: rotate(45deg);

    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;

    /* IE supports nothing above? Too bad, it will ignore it */
}
-1

All Articles