注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

古城风~~~

竹密无妨溪水过,天高不碍白云飞。这天下总有一份是属于我古城的天地!

 
 
 

日志

 
 

asp常用自定义函数【不定期更新】  

2013-12-20 15:01:56|  分类: asp |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
1.检查字符串是否存在于数组中:
Function isInArray(k_id, k_array)
dim flag : flag = false
for i=0 to ubound(k_array)-1
if k_id=k_array(i) then
flag = true
exit for
end if
next
isInArray = flag
End Function

用法:
<%
dim dingdan_id
dim dingdan_array
dingdan_array = Array("2102110","2102143","2102190","2102200","2102202","2102216")
dingdan_id = "2102200"

if isInArray(dingdan_id, dingdan_array) then
response.Write("单号:"&dingdan_id&"存在数组中")
else
response.Write("单号:"&dingdan_id&"不存在数组中")
end if

Function isInArray(k_id, k_array)
dim flag : flag = false
for i=0 to ubound(k_array)-1
if k_id=k_array(i) then
flag = true
exit for
end if
next
isInArray = flag
End Function
%>


2.判断用户来源于手机或电脑:
Function isMobile()
dim mobile_flag : mobile_flag = false
if Request.ServerVariables("HTTP_X_WAP_PROFILE") then '如果有HTTP_X_WAP_PROFILE则是手机
mobile_flag = true
end if
'如果只支持wml并且不支持html则是手机
if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") > 0 And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html")=0 then
mobile_flag = true
end if
'如果支持wml和html但是wml在html之前则是移动设备
if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") then 
   if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml")< InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") then 
mobile_flag = true
   end if
end if
'如果手机User_Agent有品牌特征符则是手机
Set reg = New RegExp
str="iphone,ipod,ipad,ios,android,nokia,motorola,^mot\-,softbank,foma,docomo,kddi,up\.browser,up\.link,htc,dopod,blazer,netfront,helio,hosin,huawei,novarra,CoolPad,webos,techfaith,palmsource,blackberry,alcatel,amoi,ktouch,nexian,samsung,^sam\-,s[cg]h,^lge,ericsson,philips,sagem,wellcom,bunjalloo,maui,symbian,smartphone,midp,wap,phone,windows ce,iemobile,^spice,^bird,^zte\-,longcos,pantech,gionee,^sie\-,portalmmm,jig\s browser,hiptop,^ucweb,^benq,haier,^lct,opera\s*mobi,opera\*mini,320x320,240x320,176x220"
str=Replace(str,",",")|(")
reg.pattern=".*("&str&").*"
reg.IgnoreCase = True
'response.write str&"<BR>"&reg.pattern
if reg.test(Request.ServerVariables("HTTP_USER_AGENT")) then 
mobile_flag = true
end if
isMobile = mobile_flag

End Function

用法:
<%
Function isMobile()
dim mobile_flag : mobile_flag = false
if Request.ServerVariables("HTTP_X_WAP_PROFILE") then '如果有HTTP_X_WAP_PROFILE则是手机
mobile_flag = true
end if
'如果只支持wml并且不支持html则是手机
if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") > 0 And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html")=0 then
mobile_flag = true
end if
'如果支持wml和html但是wml在html之前则是移动设备
if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml") And InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") then 
   if InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"vnd.wap.wml")< InStr(LCase(Request.ServerVariables("HTTP_ACCEPT")),"text/html") then 
mobile_flag = true
   end if
end if
'如果手机User_Agent有品牌特征符则是手机
Set reg = New RegExp
str="nokia,iphone,ipod,ipad,ios,android,motorola,^mot\-,softbank,foma,docomo,kddi,up\.browser,up\.link,htc,dopod,blazer,netfront,helio,hosin,huawei,novarra,CoolPad,webos,techfaith,palmsource,blackberry,alcatel,amoi,ktouch,nexian,samsung,^sam\-,s[cg]h,^lge,ericsson,philips,sagem,wellcom,bunjalloo,maui,symbian,smartphone,midp,wap,phone,windows ce,iemobile,^spice,^bird,^zte\-,longcos,pantech,gionee,^sie\-,portalmmm,jig\s browser,hiptop,^ucweb,^benq,haier,^lct,opera\s*mobi,opera\*mini,320x320,240x320,176x220"
str=Replace(str,",",")|(")
reg.pattern=".*("&str&").*"
reg.IgnoreCase = True
'response.write str&"<BR>"&reg.pattern
if reg.test(Request.ServerVariables("HTTP_USER_AGENT")) then 
mobile_flag = true
end if
isMobile = mobile_flag

End Function

dim root_path
if LCase(Request.ServerVariables("Https"))="off" then
root_path = "http://"
else
root_path = "https://"
end if
if Request.ServerVariables("Server_Port")="80" then
root_path = root_path & request.ServerVariables("SERVER_NAME")
else
root_path = root_path & request.ServerVariables("SERVER_NAME") & ":" & Request.ServerVariables("Server_Port")
end if
%>
<%
if isMobile() then
'Response.Status="301 Moved Permanently"
'Response.AddHeader "Location" , root_path&"/m_login.asp"
'Response.End()
response.Redirect(root_path&"/m_login.asp")
else

'Response.Status="301 Moved Permanently"
'Response.AddHeader "Location" , root_path&"/login.asp"
'Response.End()
response.Redirect(root_path&"/login.asp")
end if
%>
  评论这张
 
阅读(435)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017