PHP Code to Detect IE Browsers

P

The extremely buggy way that Internet Explorer renders CSS annoyed me again, this time because of the different way it displays elements with z-indexes.

I spent a couple of hours trying to fix the bug, failed, and decided to go about it another way. The problem lay in a CSS/Javascript rotating banner gallery ,so I used PHP to redirect all Internet Explorer users to a static version of that instead.

Here’s the PHP code that I used. This is the function, put it anywhere in your PHP file:

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

And this is how I called it:


if detectIE() {
//if true, means the user's on IE
//do all the IE stuff here...
} else {
//all is fine
//use normal code here
}

Similar Posts:

About the author

Alvin Poh

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world.

Read more about my story here.

2 comments

  • When I opened up my website using Mozilla firefox all are fine, the alignment of table are Ok, But when I opened up my website using IE or Internet Explorer all are ugly looking, like the alignment of table are not perfect.

By Alvin Poh

About Author

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world.

Read more about my story here.