Solved

Determine a Mobile OS with ASP

Posted on 2011-03-20
5
554 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now