首页  >  新闻资讯 > ASP 中如何判断PC用户访问还是手机用户访问

ASP 中如何判断PC用户访问还是手机用户访问

  
  1. <%
  2. '判断是否是手机上网
  3. 'response.write Request.ServerVariables("HTTP_ACCEPT")&"<BR>"
  4. 'response.write Request.ServerVariables("HTTP_USER_AGENT")&"<BR>"
  5. URL="http://www.iscripts.org/?mobile=yes"
  6. If Request.ServerVariables("HTTP_X_WAP_PROFILE") Then '如果有HTTP_X_WAP_PROFILE则是手机
  7. ' response.write "手机用户1"
  8. response.redirect URL
  9. response.End
  10. End If
  11. '如果只支持wml并且不支持html则是手机
  12. If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") > 0 And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html")=0 Then
  13. ' Response.write "手机用户2"
  14. response.redirect URL
  15. response.End
  16. End If
  17. '如果支持wml和html但是wml在html之前则是移动设备
  18. If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") Then
  19. If InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml")< InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") Then
  20. ' Response.write "手机用户3"
  21. response.redirect URL
  22. respone.End
  23. End If
  24. End If
  25. '如果手机User_Agent有品牌特征符则是手机
  26. Set reg = New RegExp
  27. str="CECT,Compal,CTL,LG,NEC,TCL,Alcatel,Ericsson,BIRD,DAXIAN,DBTEL,Eastcom,PANTECH,Dopod,PHILIPS,HAIER,KONKA,KEJIAN,LENOVO,BenQ,MOT,Soutec,Nokia,SAGEM,SGH,SED,Capitel,Panasonic,SonyEricsson,SIE,SHARP,Amoi,PANDA,ZTE"
  28. str=Replace(str,",",")|(")
  29. reg.pattern=".*("&str&").*"
  30. reg.IgnoreCase = True
  31. response.write str&"<BR>"&reg.pattern
  32. If reg.test(Request.ServerVariables("HTTP_USER_AGENT")) Then
  33. ' response.write "手机用户4"
  34. response.redirect URL
  35. respone.End
  36. End If
  37. %>



第二种,这个效果会好一些

  
  1. HTTP_ACCEPT=Request.ServerVariables("HTTP_ACCEPT") '获取浏览器信息
  2. HTTP_USER_AGENT=LCase(Request.ServerVariables("HTTP_USER_AGENT")) '获取AGENT
  3. HTTP_X_WAP_PROFILE=Request.ServerVariables("HTTP_X_WAP_PROFILE") 'WAP特定信息 品牌机自带浏览都会
  4. HTTP_UA_OS=Request.ServerVariables("HTTP_UA_OS") '手机系统 电脑为空
  5. HTTP_VIA=LCase(Request.ServerVariables("HTTP_VIA")) '网关信息
  6. Dim WapStr
  7. WAPstr=False
  8. If ubound(split(HTTP_ACCEPT,"vnd.wap"))>0 Then WAPstr=True
  9. If HTTP_USER_AGENT="" Then WAPstr=True
  10. If HTTP_X_WAP_PROFILE<>"" Then WAPstr=True
  11. If HTTP_UA_OS<>"" Then WAPstr=True
  12. IF ubound(split(HTTP_VIA,"wap"))>0 Then WAPstr=True
  13. IF ubound(split(HTTP_USER_AGENT,"netfront"))>0 Then WAPstr=True
  14. IF ubound(split(HTTP_USER_AGENT,"iphone"))>0 Then WAPstr=True
  15. IF ubound(split(HTTP_USER_AGENT,"opera mini"))>0 Then WAPstr=True
  16. IF ubound(split(HTTP_USER_AGENT,"ucweb"))>0 Then WAPstr=True
  17. IF ubound(split(HTTP_USER_AGENT,"windows ce"))>0 Then WAPstr=True
  18. IF ubound(split(HTTP_USER_AGENT,"symbianos"))>0 Then WAPstr=True
  19. IF ubound(split(HTTP_USER_AGENT,"java"))>0 Then WAPstr=True
  20. IF ubound(split(HTTP_USER_AGENT,"android"))>0 Then WAPstr=True
  21. If WAPstr=True Then
  22. Response.Write "请访问手机版本http://m.logo880.cn"
  23. response.redirect "http://m.logo880.cn"
  24. response.end
  25. else
  26. 'response.redirect "http://www.logo880.cn"
  27. 'response.end
  28. End if
  29. %>

最新评论

0条评论

    暂无评论,欢迎您评论。

热门阅读