asp下通過HTTP_USER_AGENT判斷用戶是從手機(jī)上訪問,還是電腦IE上訪問
更新時(shí)間:2011年01月06日 14:34:15 作者:
最近wap網(wǎng)站比較流行,我們需要判斷下客戶使用手機(jī)訪問的還是電腦ie訪問的, 好給出不同尺寸的頁面,更符合用戶瀏覽習(xí)慣,下面是核心判斷代碼,需要的朋友可以參考下。
通過HTTP_USER_AGENT判斷用戶是從手機(jī)上訪問,還是電腦IE上訪問。
asp代碼片段:主要使用了正則匹配手機(jī)環(huán)境,大家可以補(bǔ)充手機(jī)平臺(tái)。
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern = "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile|ipod|iphone|android|opera mini|blackberry|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile"
agent = request.ServerVariables("HTTP_USER_AGENT") & ""
if agent <> "" then
if not regex.test(agent) then
'不是從手機(jī)來的訪問,跳轉(zhuǎn)到y(tǒng)our.domain.com
response.redirect("http://your.domain.com")
end if
end if
感謝老曹提供的asp代碼。
dragonchen82@hotmail.com
asp代碼片段:主要使用了正則匹配手機(jī)環(huán)境,大家可以補(bǔ)充手機(jī)平臺(tái)。
復(fù)制代碼 代碼如下:
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern = "mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile|ipod|iphone|android|opera mini|blackberry|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile"
agent = request.ServerVariables("HTTP_USER_AGENT") & ""
if agent <> "" then
if not regex.test(agent) then
'不是從手機(jī)來的訪問,跳轉(zhuǎn)到y(tǒng)our.domain.com
response.redirect("http://your.domain.com")
end if
end if
感謝老曹提供的asp代碼。
dragonchen82@hotmail.com
相關(guān)文章
Asp函數(shù)介紹(37個(gè)常用函數(shù))
下面的函數(shù)是asp中經(jīng)常用的到呢,大家可以收藏一下經(jīng)常查詢下2008-11-11asp下實(shí)現(xiàn)UrlEncoding轉(zhuǎn)換編碼的代碼
asp下實(shí)現(xiàn)UrlEncoding轉(zhuǎn)換編碼的代碼...2007-09-09不能使用“;文件已在使用中 Microsoft JET Database Engine
不能使用 '';文件已在使用中。說明: 執(zhí)行當(dāng)前 Web 請(qǐng)求期間,出現(xiàn)未處理的異常。請(qǐng)檢查堆棧跟蹤信息,以了解有關(guān)該錯(cuò)誤以及代碼中導(dǎo)致錯(cuò)誤的出處的詳細(xì)信息2012-06-06比較詳細(xì)的Asp偽靜態(tài)化方法及Asp靜態(tài)化探討
本站已經(jīng)收藏了不少關(guān)于偽靜態(tài)的文章,這篇文章本站已經(jīng)有了,但主要考慮比較詳細(xì),大家可以參考下2008-08-08asp Response.flush 實(shí)時(shí)顯示進(jìn)度
如果你知道Response.Flush和Response.Clear,那你就可以不用這樣的等待了。每生成一個(gè)Html頁面,就用Response.write立即返回一條信息,提示該條數(shù)據(jù)庫記錄已經(jīng)生成Html。2008-08-08asp中去除內(nèi)容HTML標(biāo)簽的三個(gè)function函數(shù)
asp中去除內(nèi)容HTML標(biāo)簽的三個(gè)function函數(shù)...2007-03-03