Connecting Tech Pros Worldwide Forums | Help | Site Map

Server Side Scripting for Mobile Detection and Redirection

Newbie
 
Join Date: May 2007
Location: Texas
Posts: 9
#1: May 21 '07
Hi all...

I need some help figuring out what sort of script is needed to first: detect if a viewer is coming from a mobile device and second: if so, redirect the viewer to the mobile site.

IIS Server
home site: site.com
mobile site: site.com/mobile

I have researched and found code to implement... but it was for an .htaccess file for use on APACHE.

(Someone in the mobile site forum suggested I post in this one)

Thanks in advance...

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: May 21 '07

re: Server Side Scripting for Mobile Detection and Redirection


What are you using to detect? ASP can't really help at that point, javascript maybe?

Jared
Newbie
 
Join Date: May 2007
Location: Texas
Posts: 9
#3: May 22 '07

re: Server Side Scripting for Mobile Detection and Redirection


Here is what we have so far... placed in the head of the original index.html file:

<%
userAgent = Request.ServerVariables("HTTP_USER_AGENT")
isMobile = false
if((InStr(userAgent, "AvantGo") > 0) OR (InStr(userAgent, "Windows CE") > 0) OR (InStr(userAgent, "NetFront") > 0) OR (InStr(userAgent, "BlackBerry") > 0) ) then
isMobile = true
end if
if isMobile then
response.redirect("http://www.namesandnumbers.com/mobile")
end if
%>

Seems to be doing the trick... just had to save the index.html file to an index.asp file and then had the server point to the .asp as priority.

We will then add any other "mobile" users to the list above for detection...
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: May 24 '07

re: Server Side Scripting for Mobile Detection and Redirection


Ah, detected thru the server variables, I hadn't thought to do it that way. Good job and thanks for posting your solution.

Jared
Reply


Similar ASP / Active Server Pages bytes