问题发布与回答 发表于 2021-5-1 21:15:04

ASP判断手机访问网站并跳转指定页面的代码

**种:通过http协议头判断是否存在手机登陆站点的特征码
代码如下:
HTTP_ACCEPT=Request.ServerVariables("HTTP_ACCEPT")               '获取浏览器信息
HTTP_USER_AGENT=LCase(Request.ServerVariables("HTTP_USER_AGENT"))'获取AGENT
HTTP_X_WAP_PROFILE=Request.ServerVariables("HTTP_X_WAP_PROFILE")   'WAP特定信息 品牌机自带浏览器都会有
HTTP_UA_OS=Request.ServerVariables("HTTP_UA_OS")                   '手机系统 电脑为空
HTTP_VIA=LCase(Request.ServerVariables("HTTP_VIA"))                '网关信息
Dim WapStr
WAPstr=False
If ubound(split(HTTP_ACCEPT,"vnd.wap"))>0 Then WAPstr=True
If HTTP_USER_AGENT="" ThenWAPstr=True
If HTTP_X_WAP_PROFILE<>"" ThenWAPstr=True
If HTTP_UA_OS<>"" ThenWAPstr=True
IF ubound(split(HTTP_VIA,"wap"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"netfront"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"iphone"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"opera mini"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"ucweb"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"windows ce"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"symbianos"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"java"))>0 ThenWAPstr=True
IF ubound(split(HTTP_USER_AGENT,"android"))>0 ThenWAPstr=True
If WAPstr=True Then   
Response.Write "提醒:您访问的为手机站点"   
response.redirect "手机站点网址"
response.end
else   
'response.redirect "电脑站点网址"
'response.end
End if
第二种:通过正则表达式
Sub Check_Wap()
      dim MoblieUrl,reExp,MbStr
      MoblieUrl="http://www.17ht.com"'手机网站路径
      Set reExp = New RegExp
      MbStr="Android|iPhone|UC|Windows Phone|webOS|BlackBerry|iPod"
      reExp.pattern=".*("&MbStr&").*"
      reExp.IgnoreCase = True
      reExp.Global = True
      If reExp.test(Request.ServerVariables("HTTP_USER_AGENT")) Then
                response.redirect MoblieUrl
                response.End
      End If
End Sub
页: [1]
查看完整版本: ASP判断手机访问网站并跳转指定页面的代码