ASP编程常用代码精选集合(十二)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1:asp检查组件是否已经安装
<% '函数名:IsObjInstalled
'作用:检查组件是否已经安装
'参数:strClassString ----组件名
'返回值:True ----已经安装
' False ----没有安装
function IsObjInstalled(strClassString)
on error resume next
IsObjInstalled = False
err = 0
dim xTestObj
set xTestObj = Server.createobject(strClassString)
if0= err then IsObjInstalled = True
set xTestObj = nothing
err = 0
end function
%>
2:asp检查Email地址合法性
'********************************************
'函数名:BPCheckEMail
'作用:检查Email地址合法性
'参数:email ----要检查的Email地址
'返回值:True ----Email地址合法False ----Email地址不合法
'********************************************
Function BPCheckEMail(email)
Dim strArr,strRE1,strRE2,oRE1,oRE2,oMatches1,oMatches2
strArr = Split(email,"@")
If UBound(strArr) <> 1 Then
BPCheckEMail = False : Exit Function
End If
strRE1 = "^(?:[\w\.-]+@[A-Za-z1-9]{1}[A-Za-z0-9\.-]+\.[A-Za-z1-9]{2,3})" strRE2 = "[^\w\.@:-]+"
Set oRE1 = New RegExp : Set oRE2 = New RegExp
oRE1.Pattern = strRE1 : oRE2.Pattern = strRE2
oRE1.IgnoreCase = False : oRE2.IgnoreCase = False
oRE1.Global = True : oRE2.Global = True
Set oMatches1 = oRE1.Execute(em ail) : Set oMatches2 = oRE2.Execute(em ail) If oMatches1.Count <> 0 And oMatches2.Count = 0 Then
BPCheckEMail = True
Else
BPCheckEMail = False
End If
End Function
3: asp生成指定类型的随机字符串
'函数:RandomStr
'作用:生成指定类型的随机字符串
'参数:IsIgnoreCase(大小写字母状态)
' IsStatus(数字、字母组合)
' CodeLen(字符串长度)
Function RandomStr(ByVal IsIgnoreCase,ByVal IsStatus,ByVal CodeLen) Dim NumStr,CharStr,Str
Dim RCodeItem,RCodeStart,RCodeStr
NumStr="0123456789"
CharStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Select Case UCase(IsIgnoreCase) '选择字符串类型
Case"A":CharStr=CharStr&LCase(CharStr)
Case"U":CharStr=CharStr
Case"L":CharStr=LCase(CharStr)
Case Else:CharStr=CharStr&LCase(CharStr)
End Select
Select Case UCase(IsStatus)'输出组合类型
Case"A":Str=NumStr&CharStr
Case"N":Str=NumStr'Only Number
Case"C":Str=CharStr'Only Char
Case Else:Str=NumStr&CharStr
End Select
Randomize
For RCodeItem=0To CodeLen-1
RCodeStart=Int(Rnd*Len(Str))
RCodeStr=RCodeStr&Mid(Str,RCodeStart+1,1)
Next
RandomStr=RCodeStr
End Function
4:asp取得某个网页的内容
'取得某个网页的内容
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send
if Http.readystate<>4then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0then
err.Clear
end if
end function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
5:asp的验证码
'asp的验证码
Sub Com_CreateValidCode(pSN)
Response.Expires = -9999
Response.AddHeader "Pr agma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"
Randomize
Dim i, ii, iii
Const cOdds = 8'杂点出现的机率
Const cAmount = 10'文字数量
Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'颜色的数据(字符,背景)
Dim vColorData(1)
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(255) ' 蓝0,绿0,红0(黑色)vColorData(1) = ChrB(235) & ChrB(235) & ChrB(235) ' 蓝250,绿236,红211(浅蓝色)
'随机产生字符
Dim vCode(4), vCodes
For i = 0To3
vCode(i) = Int(Rnd* cAmount)
vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
Next
Session(pSN) = vCodes '记录入Session
' 字符的数据
Dim vNumberData(35)
vNumberData(0) = "1110000111110111101111011110111101001011110100101 111010010111101001011110111101111011110111110000111"
vNumberData(1) = "1111011111110001111111110111111111011111111101111 111110111111111011111111101111111110111111100000111"
vNumberData(2) = "1110000111110111101111011110111111111011111111011 111111011111111011111111011111111011110111100000011"
vNumberData(3) = "1110000111110111101111011110111111110111111100111 111111101111111111011110111101111011110111110000111"
vNumberData(4) = "1111101111111110111111110011111110101111110110111 111011011111100000011111110111111111011111111000011"
vNumberData(5) = "1100000011110111111111011111111101000111110011101 111111110111111111011110111101111011110111110000111"
vNumberData(6) = "1111000111111011101111011111111101111111110100011 111001110111101111011110111101111011110111110000111"
vNumberData(7) = "1100000011110111011111011101111111101111111110111 111110111111111011111111101111111110111111111011111"
vNumberData(8) = "1110000111110111101111011110111101111011111000011 111101101111101111011110111101111011110111110000111"
vNumberData(9) = "1110001111110111011111011110111101111011110111001 111100010111111111011111111101111011101111110001111"
vNumberData(10) = "111101111111110111111110101111111010111111101011 1111101011111100000111110111011111011101111000100011"
vNumberData(11) = "100000011111011110111101111011110111011111000011 1111011101111101111011110111101111011110111000000111"
vNumberData(12) = "111000001111011110111011111011101111111110111111 1110111111111011111111101111101111011101111110001111"
vNumberData(13) = "100000111111011101111101111011110111101111011110 1111011110111101111011110111101111011101111000001111"
vNumberData(14) = "100000011111011110111101101111110110111111000011
1111011011111101101111110111111111011110111000000111"
vNumberData(15) = "100000011111011110111101101111110110111111000011 1111011011111101101111110111111111011111111000111111"
vNumberData(16) = "111000011111011101111011110111101111111110111111 1110111111111011100011101111011111011101111110001111"
vNumberData(17) = "100010001111011101111101110111110111011111000001 1111011101111101110111110111011111011101111000100011"
vNumberData(18) = "110000011111110111111111011111111101111111110111 1111110111111111011111111101111111110111111100000111"
vNumberData(19) = "111000001111111011111111101111111110111111111011 1111111011111111101111111110111110111011111000011111"
vNumberData(20) = "100010001111011101111101101111110101111111000111 1111010111111101101111110110111111011101111000100011"
vNumberData(21) = "100011111111011111111101111111110111111111011111 1111011111111101111111110111111111011110111000000011"
vNumberData(22) = "100010001111001001111100100111110010011111010101 1111010101111101010111110101011111010101111001010011"
vNumberData(23) = "100010001111001101111100110111110101011111010101 1111010101111101100111110110011111011001111000110111"
vNumberData(24) = "111000111111011101111011111011101111101110111110 1110111110111011111011101111101111011101111110001111"
vNumberData(25) = "100000011111011110111101111011110111101111000001 1111011111111101111111110111111111011111111000111111"
vNumberData(26) = "111000111111011101111011111011101111101110111110 1110111110111011111011101001101111011001111110001011"
vNumberData(27) = "100000111111011101111101110111110111011111000011 1111010111111101101111110110111111011101111000110011"
vNumberData(28) = "111000001111011110111101111011110111111111100111 1111111001111111111011110111101111011110111100000111"
vNumberData(29) = "100000001110110110111111011111111101111111110111 1111110111111111011111111101111111110111111110001111"
vNumberData(30) = "100010001111011101111101110111110111011111011101 1111011101111101110111110111011111011101111110001111"
vNumberData(31) = "100010001111011101111101110111110111011111101011 1111101011111110101111111010111111110111111111011111"
vNumberData(32) = "100101001111010101111101010111110101011111010101 1111001001111110101111111010111111101011111110101111"
vNumberData(33) = "100010001111011101111110101111111010111111110111 1111110111111110101111111010111111011101111000100011"
vNumberData(34) = "100010001111011101111101110111111010111111101011 1111110111111111011111111101111111110111111110001111"
vNumberData(35) = "110000001111011101111111110111111110111111111011 1111110111111111011111111011111111101110111100000011"
' 输出图像文件头
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & _
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & _
ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
' 输出图像信息头
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & Ch rB(0) & ChrB(176) & ChrB(4) & _
ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & _
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & C hrB(0)
For i = 9To0Step -1' 历经所有行
For ii = 0To3' 历经所有字
For iii = 1To10' 历经所有像素
' 逐行、逐字、逐像素地输出图像数据
If Rnd* 99+ 1< cOdds Then' 随机生成杂点
Response.BinaryWrite vColorData(0)
Else
Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub
dim sName
sName = request("s")
if sName = ""then
Call Com_CreateValidCode("VERIFYNUM")
else
Call Com_CreateValidCode(sName)
end if。