Showing posts with label Browsers. Show all posts
Showing posts with label Browsers. Show all posts

Wednesday, 8 April 2009

IE8 and browser detection

Do you develop websites of your own? If so you may use browser detection methods to find out what the browser used and tweak your website to look nice in other browsers.

Finally moving to IE8 and bypassing version 7 I found that the browser is not detected using PHP. In IE 7 I could use the code:

if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') )
{
$browser = 'ie7';
}

This works for 6 and 7 by changing the number. However for in PHP IE8 reports:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; MSN OptimizedIE8;ENGB)

The work around in PHP I used was "OptimizedIE8". By tweaking my detection script, I added:

if ( strpos($_SERVER['HTTP_USER_AGENT'], 'OptimizedIE8') )
{
$browser = 'ie8';
}

For those of you that like to avoid JavaScript and use PHP, I hope this helps. Others that use ASP, I'm sure you have something to combat this too.

If this still does not work on IE and my website then please let me know. Thanks.