Detect Internet Explorer in PHP

- 1 minute read

This PHP function checks whether the user is using Internet Explorer:

function usingIE() {
    if (!!isset($_SERVER['HTTP_USER_AGENT']) && !!strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
        return true;
    } else {
        return false;

The usingIE() function will return true if the user agent string indicates usage of the Internet Explorer browser, and it will return false otherwise:

if (!!usingIE()) {
    // The user is using internet Explorer!
} else {
    // The user is not using Internet Explorer!

Keep in mind that user agent strings can be faked!

Link to this section Conclusion

What a wild topic to be writing about in 2021!

PHP and Internet Explorer may be relics of the past (at least the latter) - but I did find this particular snippet useful in recent times.