edisav_edava Posted July 26, 2013 Author Report Posted July 26, 2013 <% ' File: index.asp ' Description: redirect to mobile if you are a mobile browser; ' stop redirecting if a "stop_mobi=yes" parameter is passed; ' a "stop_mobi" session cookie will be set to stop redirection for current session ' restart redirecting if a "stop_mobi=no" parameter is passed; ' Copyright: Usablenet Inc. Function CheckStringForMobileUA(objDict, strString) Dim bolFound bolFound = False Dim strKey If InStr(1, strString, "UsableNet", vbTextCompare) <= 0 then For Each strKey in objDict If InStr(1, strString, strKey, vbTextCompare) > 0 then bolFound = True Exit For End If Next End If CheckStringForMobileUA = bolFound End Function Dim objDictMUA Set objDictMUA = Server.CreateObject("Scripting.Dictionary") objDictMUA.Add "Android", "" objDictMUA.Add "AU-MIC", "" objDictMUA.Add "AUDIOVOX-", "" objDictMUA.Add "Alcatel", "" objDictMUA.Add "BlackBerry", "" objDictMUA.Add "Blazer", "" objDictMUA.Add "Danger hiptop", "" objDictMUA.Add "DoCoMo/", "" objDictMUA.Add "Ericsson", "" objDictMUA.Add "Googlebot-Mobile", "" objDictMUA.Add "MSN Mobile *****", "" objDictMUA.Add "Handheld", "" objDictMUA.Add "HTC_HD2_T58585 Opera", "" objDictMUA.Add "iPhone", "" objDictMUA.Add "iPod", "" objDictMUA.Add "Klondike", "" objDictMUA.Add "LG-", "" objDictMUA.Add "LGE-", "" objDictMUA.Add " LGE ", "" objDictMUA.Add "MOT-", "" objDictMUA.Add "NetFront", "" objDictMUA.Add "Nokia", "" objDictMUA.Add "NokiaN8", "" objDictMUA.Add "Novarra-Vision", "" objDictMUA.Add "Opera Mini", "" objDictMUA.Add "PalmOS", "" objDictMUA.Add "PalmSource", "" objDictMUA.Add "Panasonic-", "" objDictMUA.Add "SAGEM-", "" objDictMUA.Add "SAMSUNG", "" objDictMUA.Add "SGH-", "" objDictMUA.Add "SHARP-", "" objDictMUA.Add "SIE-", "" objDictMUA.Add "Samsung-", "" objDictMUA.Add "Smartphone", "" objDictMUA.Add "Sony", "" objDictMUA.Add "Symbian OS", "" objDictMUA.Add "webOS", "" objDictMUA.Add "Windows CE", "" objDictMUA.Add "Windows Mobile", "" objDictMUA.Add "Windows Phone", "" objDictMUA.Add "nokia", "" objDictMUA.Add "portalmmm", "" objDictMUA.Add "Profile/MIDP-", "" objDictMUA.Add "UP.Link", "" objDictMUA.Add "UP.Browser", "" objDictMUA.Add "XV6875", "" Dim userAgent Dim stopMobiParam Dim stopMobiCookie Dim mobiRedirect userAgent = Request.ServerVariables("HTTP_USER_AGENT") stopMobiParam = Request.QueryString("stop_mobi") stopMobiCookie = Request.Cookies("stop_mobi") mobiRedirect = False If stopMobiParam="yes" Then stopMobiCookie="yes" ' stop_mobi cookie expires at the end of current session Response.Cookies("stop_mobi")="yes" ' use the following to make stop_mobi cookie expire in 1 day ' Response.Cookies("stop_mobi").Expires=Date+1 ElseIf stopMobiParam="no" Then stopMobiCookie="no" Response.Cookies("stop_mobi")="" Response.Cookies("stop_mobi").Expires=Date-1 End If If stopMobiCookie<>"yes" And Len(userAgent) > 0 And CheckStringForMobileUA(objDictMUA, userAgent) Then mobiRedirect = True End If If mobiRedirect then Response.Redirect("http://mobile.usablenet.com/mt/my website/") Else Response.Redirect("my website") End If %>
Recommended Posts