Google

Sunday, September 30, 2007

How to identify a mobile phone hitting your web site

I have seen a lot of mobile headers, and here are just a few …

Blackberry
[Profile] => http://www.blackberry.net/go/mobile/profiles/uaprof/7290/4.0.0.rdf
[User-Agent] => BlackBerry7290/4.0.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Link/5.1.2.5
[Accept] => application/vnd.rim.html, text/html, text/plain, application/xhtml+xml, application/vnd.wap.xhtml+xml, application/vnd.wap.wml+xml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, image/gif;anim=1, image/jpg, image/vnd.wap.wbmp, image/png, image/vnd.rim.png, image/jpeg, image/pjpeg, application/smil, application/x-vnd.rim.pme, application/x-vnd.rim.pme.b, image/pme, application/vnd.oma.drm.message, audio/midi, audio/x-midi, audio/mid, application/x-javascript, application/vnd.rim.jscriptc;v=0-8-8, text/css;media=handheld, application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.alternative, application/vnd.wap.multipart.related, multipart/mixed, multipart/alternative, multipart/related, text/vnd.sun.j2me.app-descriptor, application/java-archive, application/vnd.rim.proxyconfig, application/vnd.wap.coc, application/vnd.wap.slc, application/vnd.wap.sic, text/vnd.wap.co, text/vnd.wap.sl, text/vnd.wap.si, application/x-x509-ca-cert, application/x-x509-email-cert, application/x-x509-server-cert, application/x-x509-user-cert, application/vnd.wap.signed-certificate, application/vnd.wap.cert-response, application/vnd.wap.wtls-ca-certificate, image/bmp, image/vnd.wap.wbmp, text/x-wap.wml, text/vnd.wap.wml, text/x-hdml, text/html, text/vnd.wap.wmlscript, text/vnd.wap.co, text/vnd.wap.si, text/vnd.wap.sl, */*

Siemens SK65
[user-agent] => SIE-SK6R/46 UP.Browser/7.0.2.2.d.1.100(GUI) MMP/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1
[x-wap-profile] => "http://communication-market.siemens.de/portal/UAProf/UAP.aspx?device=SK6R&v=46"

SonyEricsson K600i
[Accept] => application/vnd.wap.xhtml+xml, application/vnd.wap.wmlc, application/xhtml+xml, image/gif, */*; q=0.9
[Accept-Charset] => utf-8, utf-16, iso-8859-1, iso-10646-ucs-2, Shift_JIS
[User-Agent] => SonyEricssonK600i/R2K/SN356573000470498 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1
[x-wap-profile] => "http://wap.sonyericsson.com/UAprof/K600iR101.xml"
[Max-Forwards] => 10
[X-Forwarded-For] => xxx.xxx.xxx.xxx

SonyEricsson K750i
[accept] => application/vnd.wap.xhtml+xml, application/vnd.wap.wml, application/xhtml+xml, multipart/mixed, application/vnd.wap.multipart.mixed, image/gif, */*; q=0.9
[accept-charset] => utf-8, utf-16, iso-8859-1, iso-10646-ucs-2, Shift_JIS
[accept-language] => en
[user-agent] => SonyEricssonK750i/R1L Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1
[x-wap-profile] => "http://wap.sonyericsson.com/UAprof/K750iR101.xml"

Nokia 6030
[Host] => 000.000.000.000
[accept] => application/vnd.wap.wmlscriptc, text/vnd.wap.wml, application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html, multipart/mixed, */*
[accept-charset] => ISO-8859-1, US-ASCII, UTF-8; Q=0.8, ISO-10646-UCS-2; Q=0.6
[accept-encoding] => gzip, deflate
[user-agent] => Nokia6030/2.0 (y3.32) Profile/MIDP-2.0 Configuration/CLDC-1.1
[x-wap-profile] => "http://nds1.nds.nokia.com/uaprof/N6030r100.xml"

Nokia 7250i
[user-agent] => Nokia7250I/1.0 (3.22) Profile/MIDP-1.0 Configuration/CLDC-1.0
[x-wap.tod-coded] => Thu, 01 Jan 1970 00:00:00 GMT
[if-modified-since] => Tue, 1 Jan 2007 01:02:03 GMT
[accept] => text/css, text/html, application/vnd.wap.xhtml+xml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, application/vnd.wap.wbxml, application/xhtml+xml, application/wml+xml, application/vnd.wap.xhtml+xml, application/x-wap-prov.browser-settings, application/x-nokia.settings, text/x-vcard, text/x-vcalendar, application/vnd.wap.wtls-ca-certificate, application/vnd.wap.hashed-certificate, application/vnd.wap.signed-certificate, application/vnd.wap.cert-response, application/vnd.wap.sic, application/vnd.wap.slc, application/x-wap-prov.browser-bookmarks, text/x-co-desc, application/vnd.oma.drm.message, image/gif, image/jpeg, image/jpg, image/bmp, image/png, image/vnd.wap.wbmp, image/vnd.nok-wallpaper, image/vnd-nok-camera-snap, image/vnd-nok-camera-snsp, application/vnd.wap.mms-message, text/vnd.sun.j2me.app-descriptor, application/vnd.nokia.ringing-tone, audio/midi, audio/mid, audio/x-midi, audio/x-mid, audio/sp-midi, application/java, image/vnd.nok-oplogo-color, application/java-archive, application/x-java-archive, text/vnd.wap.wml, text/vnd.wap.wmlscript, */*;q=0.001
[accept-charset] => iso-8859-1, utf-8;q=0.800, us-ascii;q=0.700, iso-10646-ucs-2;q=0.600, *;q=0.001


What is the easiest way to identify if its an actual mobile hitting your browser? Well to me it was checking the user-agent contains MIDP. Eg: Profile/MIDP-2.0. I used to think checking for MIDP-2.0 was the way to go. All the new phones are identified by it, and in most cases it would mean it was colour, and had java etc. But It wasn’t until the google bot hit my site that I now just check for MIDP

Eg: The Google Bot User Agent String
Nokia6820/2.0 (4.83) Profile/MIDP-1.0 Configuration/CLDC-1.0 
(compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)

A small snippet of PHP code I use to check if it’s a mobile :
if (stristr($_SERVER['HTTP_USER_AGENT'], "MIDP")){
$mobile=true;
}


And another piece of code I use for the mobile phones is the HTTP_ACCEPT header
if(stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")){
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}

Now it must be my lucky day as now Google is indexing my mobile site even though my webmaster sitemaps.xml are submitted as Mobile/XHTML

No comments: