Friday, February 12, 2010

Lessons Learned Creating a Browser Test Using XHTML, PHP and JavaScript

You're going to need information delivered by the client useragent going into PHP. To do this add the following code
$cua = $_SERVER['HTTP_USER_AGENT'];
You then need to strip out the various parts you're going to need. See image below.

image create by CC Hameed
For example, I stripped out the items between the brackets and added them to an array.
using things like stripos($ua, '(');
Here we start to find a few Windows issues.
If you also need to know what Window version your are using you will need to take the Platform token and interpret it. Eg
'Windows NT 6.1' = 'Windows 7'
'Windows NT 6.0' = 'Windows Vista'
'Windows NT 5.2' = 'Windows Server 2003 or Windows XP x64 Edition'
'Windows NT 5.1' = 'Windows XP'

Another Windows problem. If you put your browser test on a server IE version 8.0 can report itself as IE 7.0. So you need to pick out the word 'trident' from your user agent and force it to appear the browser such as this JavaScript which you can change for PHP:
string browserType = Request.Browser.Type;
// IE8 is not reported in browser type but it can be detected
// by word "Trident" in the user agent if (Request.UserAgent.ToUpper().Contains("TRIDENT")) browserType = browserType.Replace("IE7", "IE8");

That's all for now.

No comments:

Post a Comment