The Lamp är en webbyrå med passion för webbstandarder. Vi jobbar med alla typer av kunder, både stora och små. The Lamp står för hållbara och genomtänkta strategier där kundens behov och budget står i fokus. The Lamp drivs av mig och min kollega Johan Jansson. Läs mer »
Om du vill komma i kontakt med Adam eller Johan besöka oss på våra webbsidor:
Johan Jansson (Art Director)
Adam Rehal (Web Developer)
2009 23/03

Detect older versions of IE with PHP

Here’s a snippet of code that can detect what version of Internet Explorer a user is using to browse your page. If the version number is below what you specified you can easily tell them to update, redirect them somewhere or just tell them to get lost. The code is very simple:

1
2
3
4
5
6
7
8
// Set $badver to the IE version (and below) that you want to detect
$badver = 6;
$statement = 'MSIE ([0-'.$badver.']\.[0-'.$badver.'])';
ereg($statement,$_SERVER['HTTP_USER_AGENT'],$reg);
if(isset($reg[1])) { 
	// If browser version is $badver or below
	echo 'Version ' . $badver . ' or below!';
}

If you want to use this, just copy and paste the above code into the top of your page. This code is based on Karol Krizka’s function found here.

Kort på svenska. Använd koden ovan för att avgöra om användaren använder en gammal version av Internet explorer. Kan vara gött att skicka IE6-användare dit pepparn växer.

2 kommentarer
, ,