ASP的常用的自定义函数大全

2015-08-12 16:01:47来源:作者:人点击

 <%

'================================

'函数列表:
'1: 建立数据库的连接 ConnOpen(DataBaseConnectStr,DBType,Conn_object)
'2: 断开数据库的连接 ConnClose(Conn_object)
'3: 防止SQL注入 SafeRequest(paraName,paraType)
'4: 格式化日期 DateFormat(dateStr,dateType)
'5: 显示错误提示 ShowErr(errStr)
'6: 查询字符串中特定数据 SelectStr(contentStr,patternStr,patternNum)
'7: 过滤指定字符 Leach(contentStr,badWords)
'8: 远程文件内容抓取 Seize(urlStr)
'9: 数据流编码处理 BytesToBstr(body,cset)
'10: 编码cookies codeCookie(contentStr)
'11: 解码cookies DecodeCookie(contentStr)
'12: 检验数据提交来源是否合法 ChkPost()
'13: 个性化加密 MyEncrypt(StrPassword)
'14: 禁止浏览器缓存本页 NoBuffer()
'15: 网页格式化输入文本 HTMLEncode(fString)
'16: 从头部截取字符串的指定长度(按字符数算) GotTopic(Str,StrLen)
'17: 检测验证码 CheckRadomPass(RadomPass)
'18: 生成验证码 GetCode()
'19: 获取客户端操作系统版本 GetSystem()
'20: 数据库事务处理 ConnManage(Conn_object)
'21: 快速排序(递归) QuickSort(arr,Low,High)
'22: 将数组的元素以特定字符串连起来 arr_join(arr,character)
'23: 返回字符串以某分割符分割的数目 count_character(str,character)
'24: 截取含有分割符的字符串中指定数目的字符串 inter_str_by_character_num(str,character,start,num)
'25: 利用Stream下载文件 downloadFile(strFile)
'26: 返回信息 send_back(ResultWords)
'27: 获取错误信息 get_err()
'28: 与SafeRequest相反 SafeResponse(content)
'29: 保存远程图片 SaveRemoteFile(LocalFileName,RemoteFileUrl)
'30: ...
dim language_arr(10)
language_arr(0) = "数据库连接的参数设置错误!"
language_arr(1) = "数据库连接的类型参数设置错误!"
language_arr(2) = "数据库连接失败!"
language_arr(3) = "非法的参数值!"
language_arr(4) = "参数值不是有效的日期格式!"
language_arr(5) = "操作失败!"
language_arr(6) = "栏目有重名!"
language_arr(7) = "栏目名称为空!"
language_arr(8) = "栏目文件夹创建失败!"
language_arr(9) = "您没有此权限!"
'
'函数ID:1
'函数作用:建立数据库的连接
'修改时间:
'传人参数:
' connectStr:数据库连接字符串
' connectType:数据库类别-数字型,0为Access,1为MS SQL
'返回值:
'

sub ConnOpen(DataBaseConnectStr,DBType,Conn_object)
Set Conn_object = Server.Createobject("adodb.connection")
if DataBaseConnectStr = "" then call ShowErr(language_arr(0))
if DBType = 0 then
Conn_object.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DataBaseConnectStr
elseif DBType = 1 then
Conn_object.Open "Provider=SQLOLEDB.1;" & DataBaseConnectStr
else
call ShowErr(language_arr(1))
end if
err.clear
end sub
'

'函数ID:2
'函数作用:断开数据库的连接
'修改时间:
'传人参数:
'返回值:
'

Sub ConnClose(Conn_object)
Conn_object.close
set Conn_object = nothing
End sub
'

'函数ID:3
'函数作用:防止SQL注入
'修改时间:
'传人参数:
' paraName:参数名称-字符型
' paraType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符) 
'返回值:
' 过滤后的字符串
'

Function SafeRequest(paraName,paraType)
dim paraValue
paraValue = Request(paraName)
select case paraType
case 0
paraValue = replace(paraValue,"'","[system:34]")
paraValue = replace(paraValue,"=","[system:61]")
case 1
if not IsNumeric(paraValue) then call ShowErr(language_arr(3))
case -1
if not IsNumeric(paraValue) then call ShowErr(language_arr(3))
if paraValue = "" then paraValue = 0
case else
if len(paraValue) > paraType then call ShowErr(language_arr(3))
paraValue = replace(paraValue,"'","[system:34]")
paraValue = replace(paraValue,"=","[system:61]")
end select
SafeRequest = paraValue
End function
'==============================='函数ID:4
'函数作用:格式化日期
'修改时间:
'传人参数:
' dateStr:日期字符串
' paraType:日期类型-数字型
'返回值:
' 格式化后的日期
Function DateFormat(dateStr,dateType)
Dim dateString
if IsDate(dateStr) = False then
call ShowErr(language_arr(4))
end if
Select Case dateType
Case "1"
dateString = Year(dateStr)&"-"&Month(dateStr)&"-"&Day(dateStr)
Case "2"
dateString = Year(dateStr)&"."&Month(dateStr)&"."&Day(dateStr)
Case "3"
dateString = Year(dateStr)&"/"&Month(dateStr)&"/"&Day(dateStr)
Case "4"
dateString = Month(dateStr)&"/"&Day(dateStr)&"/"&Year(dateStr)
Case "5"
dateString = Day(dateStr)&"/"&Month(dateStr)&"/"&Year(dateStr)
Case "6"
dateString = Month(dateStr)&"-"&Day(dateStr)&"-"&Year(dateStr)
Case "7"
dateString = Month(dateStr)&"."&Day(dateStr)&"."&Year(dateStr)
Case "8"
dateString = Month(dateStr)&"-"&Day(dateStr)
Case "9"
dateString = Month(dateStr)&"/"&Day(dateStr)
Case "10"
dateString = Month(dateStr)&"."&Day(dateStr)
Case "11"
dateString = Month(dateStr)&language_arr(6)&Day(dateStr)&language_arr(7)
Case "12"
dateString = Day(dateStr)&language_arr(7)&Hour(dateStr)&language_arr(8)
case "13"
dateString = Day(dateStr)&language_arr(7)&Hour(dateStr)&language_arr(8)
Case "14"
dateString = Hour(dateStr)&language_arr(8)&Minute(dateStr)&language_arr(9)
Case "15"
dateString = Hour(dateStr)&":"&Minute(dateStr)
Case "16"
dateString = Year(dateStr)&language_arr(5)&Month(dateStr)&language_arr(6)&Day(dateStr)&language_arr(7)
Case Else
dateString = dateStr
End Select
DateFormat = dateString
End Function
'
'函数ID:5
'函数作用:显示错误提示
'修改时间:
'传人参数:

' errStr:错误提示-字符型
'返回值:返回提交页面
'

sub ShowErr(errStr)
Response.Write("<script>alert("""&errStr&""");location.href=""javascript:history.back()"";</script>")
Response.End
End sub

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台