How to Detect IE6 on Server Side Using PHP

Every web developer agrees that making a site work in IE6 is very difficult. Even though IE6 browser is full of bugs, its still important to make sure that the site looks ok in IE6 because of its large user base. One way to do this is to check if the web browser of end user is IE6 and then display content based on that. This is called browser sniffing.

detect-internet-explorer-on-server-side

Browser Sniffing can be done on client side (using JavaScript or CSS conditional comments) or server side depending upon your requirements. Here’s a PHP function to detect IE6 on server side,

function is_it_ie6(){
    return strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== FALSE;
}

This function returns TRUE if the end user is using IE6.

Using this function is also very easy. Just add the function in your includes file or in your php file and call it like this,

if(is_it_ie6()) {
/* do something since the visitor is using IE6 */
}
else {
/* stay calm, its not IE6 */
}

Leave a Comment