PHP: If Internet Explorer 6, 7, 8 , or 9

PHP: If internet explorer 6, 7, 8 , or 9

This is what I ended up using a variation of, which checks for IE8 and below:

if (preg_match('/MSIE\s(?P<v>\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B) && $B['v'] <= 8) {
// Browsers IE 8 and below
} else {
// All other browsers
}

How to perform Browser detection - IE (versions) in PHP

Try this:

<?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
}
?>

Why do people still use Internet Explorer 7?

Some people simply don't have a choice if their IT department has not upgraded them. If you're building your application for a specific client, build it to the lowest version they have to support. If you're just doing this on your own to publish, then just support 'modern' browser versions.

PHP detect Internet Explorer that is below version 10

The function get_browser() may be used for feature detection.

If you really want to only know the user's browser version you can look at the $_SERVER['HTTP_USER_AGENT'].

A word of caution: although most users won't do this, it is possible to send a different user agent string to the server which might be done to e.g. protect ones privacy. If someone wants to go as far as sending you a user agent to be able to use your website though they'll probably know how to deal with any bugs that may come up.

As a side question, what is the reason you're trying to limit your audience to IE 10 and up? Why not use a library such as Modernizr to fill in functions you might be missing in IE 9?

EDIT:
Some info regarding the IE 10 user agent string. You will want to read that so you know what to match your $_SERVER['HTTP_USER_AGENT'] against

How to block IE 10 and below

If I did understood your question correctly,

Put this on the very top of your PHP file, this code will detect IE 10 and below, and redirect them to your recommendation page:

if(preg_match('/(?i)msie [1-9]/',$_SERVER['HTTP_USER_AGENT']))
{
header( 'Location: recommendation.php' ) ;
}

Can I detect IE6 with PHP?

Try checking their user agent for 'MSIE 6.'.

$using_ie6 = (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== FALSE);

This is based on this user agent information.

Passing JavaScript Variable to PHP - Error in IE6, IE7 and IE8

window.innerHeight/Width are not supported by IE8 and lower. Try using document.documentElement.clientHeight/document.documentElement.clientWidth



Related Topics



Leave a reply



Submit