WAP手机网站制作,多终端页面导入自适应(主要手机和PC)

<%
htm = "index.html"
wap = "index.wml"
wap2 = "index.htm"
agent=request.ServerVariables("HTTP_USER_AGENT")
Accept = request.ServerVariables("HTTP_ACCEPT")
isWAP = false
     if (Instr(ucase(Accept),ucase("wap")) or  Instr(ucase(Accept),ucase("wml"))) then
      isWAP = true
     else
     brow = left(agent,4)
   if (ucase(brow)=ucase("Noki") or ucase(brow)=ucase("Eric") or ucase(brow)=ucase("R380") or ucase(brow)=ucase("MOT-") or ucase(brow)=ucase("UPG1") or ucase(brow)=ucase("Jing") or ucase(brow)=ucase("Acoo") or ucase(brow)=ucase("Wapt") or ucase(brow)=ucase("QWAP") or ucase(brow)=ucase("m-cr") or ucase(brow)=ucase("MC21") or ucase(brow)=ucase("Your") or ucase(brow)=ucase("YOUR") or ucase(brow)=ucase("w@pS") or ucase(brow)=ucase("Alca") or ucase(brow)=ucase("wapw") or ucase(brow)=ucase("Rain") or ucase(brow)=ucase("Java") or ucase(brow)=ucase("AUR ") or ucase(brow)=ucase("UP.B") or ucase(brow)=ucase("WAPm") or ucase(brow)=ucase("WinW") or ucase(brow)=ucase("WapI") or ucase(brow)=ucase("WAPJ") or ucase(brow)=ucase("WapV") or ucase(brow)=ucase("4thp") or ucase(brow)=ucase("Waps") or ucase(brow)=ucase("Mits") or ucase(brow)=ucase("SIE-") or ucase(brow)=ucase("Aptu") or ucase(brow)=ucase("WmlS") or ucase(brow)=ucase("Wapa")) then
       isWAP = true
    end if
    end if
       isWAP2 = false
     if (isWAP) then
       if (Instr(ucase(Accept),ucase("xhtml"))) then
         isWAP2 = true
     end if
  end if
   if (isWAP2) then
    response.Redirect(wap2)
   elseif (isWAP) then
    response.Redirect(wap)
   else
    response.Redirect(htm)
   end if
%>
<p>本页没有跳转,请手工选择您的线路</p>
<a href="/index.wml">低端手机wap</a><a href="/index.htm">高端手机xhtml</a><a href="/index.html">电脑访问</a>
其中中间用了列举法,列出常见手机的ua,还有一些常用的像op,ucweb,winwap一类的也要加上.
最后因为op有电脑版和手机版,所以如果用op没法进行选择.
Firefox:
接受:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
用户代理:Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7
OP:
接受:text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
用户代理:Opera/9.63 (Windows NT 5.2; U; Edition IBIS; zh-cn) Presto/2.1.1
IE7:
接受:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
用户代理:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
safari:
接受:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
用户代理:Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN) AppleWebKit/525.28 (KHTML, like Gecko) Version/3.2.2 Safari/525.28.1
winwap:
接受:application/vnd.wap.wmlc, text/vnd.wap.wml, image/vnd.wap.wbmp, image/gif, image/jpeg, application/vnd.wap.wmlscriptc, text/vnd.wap.wmlscript
用户代理:WinWAP/3.2 (3.2.1.25; Win32)
nokia 7610:
接受:application/vnd.wap.wmlc, text/vnd.wap.wml, image/vnd.wap.wbmp, image/gif, image/jpeg, application/vnd.wap.wmlscriptc, text/vnd.wap.wmlscript
用户代理:为空什么也不输出
 

再来个php版的.
	<?php 
$htm = "/index.html";
$wap = "/index.wml";
$wap2 = "/index.htm";
$agent=$_SERVER['HTTP_USER_AGENT'];
$Accept = $_SERVER["HTTP_ACCEPT"];
echo $agent;
$isWAP = false;
     if (substr_count(strtolower($Accept),strtolower("wap")) ||  substr_count(strtolower($Accept),strtolower("wml"))) {
      $isWAP = true;
     }else{
     $brow = substr($agent,0,4);
   if (strtolower($brow)==strtolower("Noki") || strtolower($brow)==strtolower("Eric") || strtolower($brow)==strtolower("R380") || strtolower($brow)==strtolower("MOT-") || strtolower($brow)==strtolower("UPG1") || strtolower($brow)==strtolower("Jing") || strtolower($brow)==strtolower("Acoo") || strtolower($brow)==strtolower("Wapt") || strtolower($brow)==strtolower("QWAP") || strtolower($brow)==strtolower("m-cr") || strtolower($brow)==strtolower("MC21") || strtolower($brow)==strtolower("Your") || strtolower($brow)==strtolower("YOUR") || strtolower($brow)==strtolower("w@pS") || strtolower($brow)==strtolower("Alca") || strtolower($brow)==strtolower("wapw") || strtolower($brow)==strtolower("Rain") || strtolower($brow)==strtolower("Java") || strtolower($brow)==strtolower("AUR ") || strtolower($brow)==strtolower("UP.B") || strtolower($brow)==strtolower("WAPm") || strtolower($brow)==strtolower("WinW") || strtolower($brow)==strtolower("WapI") || strtolower($brow)==strtolower("WAPJ") || strtolower($brow)==strtolower("WapV") || strtolower($brow)==strtolower("4thp") || strtolower($brow)==strtolower("Waps") || strtolower($brow)==strtolower("Mits") || strtolower($brow)==strtolower("SIE-") || strtolower($brow)==strtolower("Aptu") || strtolower($brow)==strtolower("WmlS") || strtolower($brow)==strtolower("Wapa")) {
       $isWAP = true;
}}
       $isWAP2 = false;
     if ($isWAP) {
       if (substr_count(strtolower($Accept),strtolower("xhtml"))) {
         $isWAP2 = true;
}}
   if ($isWAP2) {
    header("location:$wap2");}
   else if ($isWAP) {
     header("location:$wap");}
   else {
    header("location:$htm");
       }
?>
<p>本页没有跳转,请手工选择您的线路</p>
<a href="http://wap.reynaldliu.net/index.wml">低端手机wap</a><a href="http://www.reynaldliu.net/index.htm">高端手机xhtml</a><a href="http://www.reynaldliu.net/index.html">电脑访问</a>
 

这一个是网上搜的jsp版的,因为不会jsp也没有调试环境,不知道通不通得过,asp版和php都是我据这个修改得来.
	<%
     String htm = "/gas/index.html";
     String wap = "/wap/index.wml";
     String wap2 = "/wap2/index.xhtml";
     
     String agent = request.getHeader("user-agent");
     String accep = request.getHeader("accept");
     boolean isWAP = false;
     if (accep.toLowerCase().indexOf("vnd.wap.wml")>0){
      isWAP = true;
     }else{
      String brow = agent.substring(0,4);
      if (
       brow.equals("Noki") ||
       brow.equals("Eric") ||
       brow.equals("R380") ||
       brow.equals("MOT-") ||
       brow.equals("UPG1") ||
       brow.equals("Jing") ||
       brow.equals("Acoo") ||
       brow.equals("Wapt") ||
       brow.equals("QWAP") ||
       brow.equals("m-cr") ||
       brow.equals("MC21") ||
       brow.equals("Your") ||
       brow.equals("YOUR") ||
       brow.equals("w@pS") ||
       brow.equals("Alca") ||
       brow.equals("wapw") ||
       brow.equals("Rain") ||
       brow.equals("Java") ||
       brow.equals("AUR ") ||
       brow.equals("UP.B") ||
       brow.equals("WAPm") ||
       brow.equals("WinW") ||
       brow.equals("WapI") ||
       brow.equals("WAPJ") ||
       brow.equals("WapV") ||
       brow.equals("4thp") ||
       brow.equals("Waps") ||
       brow.equals("Mits") ||
       brow.equals("SIE-") ||
       brow.equals("Aptu") ||
       brow.equals("WmlS") ||
       brow.equals("Wapa")){
       isWAP = true;
      }
     }
     
     boolean isWAP2 = false;
     if (isWAP){
       if (accep.toLowerCase().indexOf("xhtml")>0){
         isWAP2 = true;
       }
     }
   if (isWAP2){
    response.sendRedirect(wap2);
   }else if (isWAP){
    response.sendRedirect(wap);
   }else{
    response.sendRedirect(htm);
   }
%>

Tags: wap网站 , wml网站 , xhtml mobile , wap2.0 , 手机网站

上一篇: rsyncd3.07版(客户端)常用参数理解
下一篇: [转载]批处理简述

发表评论

评论内容 (必填):

点击获得Trackback地址
My E-mail


内部参考旗下网站