Determine a Mobile OS with ASP

I have the code below to determine if the browser is a mobile version, but on Windows Mobile 7, you can choose Desktop version.  This then overrides the code.

Is there some ASP to add to what I already have to determine some of the mobile OS?

'Option Explicit
'Dim user_agent, mobile_browser, Regex, match, mobile_agents, mobile_ua, i, size
user_agent = Request.ServerVariables("HTTP_USER_AGENT")
mobile_browser = 0
Set Regex = New RegExp
With Regex
   .Pattern = "(up.browser||mmp|symbian|smartphone|midp|wap|phone|ipad|windows ce|pda|mobile|mini|palm)"
   .IgnoreCase = True
   .Global = True
End With
match = Regex.Test(user_agent)
If match Then mobile_browser = mobile_browser+1
If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/vnd.wap.xhtml+xml") Or Not IsEmpty(Request.ServerVariables("HTTP_X_PROFILE")) Or Not IsEmpty(Request.ServerVariables("HTTP_PROFILE")) Then
   mobile_browser = mobile_browser+1
end If
mobile_agents = Array("w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-")
size = Ubound(mobile_agents)
mobile_ua = LCase(Left(user_agent, 4))
For i=0 To size
   If mobile_agents(i) = mobile_ua Then
      mobile_browser = mobile_browser+1
      Exit For
   End If
If mobile_browser=0 Then 'This means site is mobile device site
   Response.Write "<p style='color:#f00;'>You have accessed our mobile version of our website."
   Response.Write "Please see <a href='' title='Credit Card Processing'>5280 Processing</a> for our full version.</p>"
End If	

Open in new window

LVL 29
Who is Participating?
GundogTrainerConnect With a Mentor Commented:
You could see how yo uget on if you add XBLWP7,ZuneWP7 to the array of user headers as they appear to be using the following in desktop mode.
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7;ZuneWP7)

Michel PlungjanIT ExpertCommented:
Why would you want to? If the visitor wants to see the non-mobile version of your siye, let them. I personally get really annoyed when a site insists on deciding I am in Germany (I'm not but the IP range is) and that my mobile is too simple to handle a real site (it isn't)
coreybryantAuthor Commented:
This is the header that the Zune gives
HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+6.1;+XBLWP7;+ZuneWP7

Open in new window

I was not looking to control the user and what they see actually, but help them.  I go to websites on my mobile phone as well, and sometimes there is too much for it to download, taking forever to download.  

Even this site will automatically direct me over to their mobile version when I go it.  I don't mind.  

Taking a look now actually at the mobile agents that I have, let's say "moto" - this would be for Motorola.  Assuming I actually understand this, any user-agent that starts with moto would have this extra code seen?  

And for the Venue Pro, could I just add "zune" - and this would include any agent that starts with zune, and no need for the XBLWP7?  Or should I also add "xbl"?

GundogTrainerConnect With a Mentor Commented:
Hadnt read your code properly - yes you could just add "zune" to the array, and \ or "xblw" rather than just "xbl" as your code on line 19 checks for the first 4 letters only.

If you need to make your array checker work for other lengths you could update your code on line 21 to read.

If mobile_agents(i) = LCase(left(user_agent,len(mobile_agents(i)))) Then

Yes it would be a bit slower and if its not broken - dont fix it.
coreybryantAuthor Commented:
Thanks for the reply.  Windows Mobile 7 has a dev browser that tells you how long it took to download the webpage.  I am sure Android has that as well (got that last week).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.