Solved

Determine a Mobile OS with ASP

Posted on 2011-03-20
5
556 Views
Last Modified: 2013-12-27
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?

Thanks!
<%
'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|up.link|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
Next
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='http://www.5280processing.com/' title='Credit Card Processing'>5280 Processing</a> for our full version.</p>"
End If	
%>

Open in new window

0
Comment
Question by:coreybryant
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35178256
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)
0
 
LVL 8

Accepted Solution

by:
GundogTrainer earned 500 total points
ID: 35179405
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)

0
 
LVL 29

Author Comment

by:coreybryant
ID: 35194623
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"?

Thanks!
0
 
LVL 8

Assisted Solution

by:GundogTrainer
GundogTrainer earned 500 total points
ID: 35231028
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.
0
 
LVL 29

Author Closing Comment

by:coreybryant
ID: 35234290
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).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wireless clients bypassing proxy, firewall instead 8 49
Best Access Point Device 25 64
DNS with WiFi Network 5 55
Linksys 4 port wireless router 62 46
Today sees the launch of a new case study, focusing on BYOD technologies we have been working with for some time now.  But with the advent of 802.11ac wireless technologies and the story behind our landmark developments, we would like to share this …
DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now