熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP的常用的自定義函數大全

2022-06-13   來源: .NET編程 

  <%

  ================================

  函數列表
建立數據庫的連接 ConnOpen(DataBaseConnectStrDBTypeConn_object)
斷開數據庫的連接 ConnClose(Conn_object)
防止SQL注入 SafeRequest(paraNameparaType)
格式化日期 DateFormat(dateStrdateType)
顯示錯誤提示 ShowErr(errStr)
查詢字符串中特定數據 SelectStr(contentStrpatternStrpatternNum)
過濾指定字符 Leach(contentStrbadWords)
遠程文件內容抓取 Seize(urlStr)
數據流編碼處理 BytesToBstr(bodycset)
編碼cookies codeCookie(contentStr)
解碼cookies DecodeCookie(contentStr)
檢驗數據提交來源是否合法 ChkPost()
個性化加密 MyEncrypt(StrPassword)
禁止浏覽器緩存本頁 NoBuffer()
網頁格式化輸入文本 HTMLEncode(fString)
從頭部截取字符串的指定長度(按字符數算) GotTopic(StrStrLen)
檢測驗證碼 CheckRadomPass(RadomPass)
生成驗證碼 GetCode()
獲取客戶端操作系統版本 GetSystem()
數據庫事務處理 ConnManage(Conn_object)
快速排序(遞歸) QuickSort(arrLowHigh)
將數組的元素以特定字符串連起來 arr_join(arrcharacter)
返回字符串以某分割符分割的數目 count_character(strcharacter)
截取含有分割符的字符串中指定數目的字符串 inter_str_by_character_num(strcharacterstartnum)
利用Stream下載文件 downloadFile(strFile)
返回信息 send_back(ResultWords)
獲取錯誤信息 get_err()
與SafeRequest相反 SafeResponse(content)
保存遠程圖片 SaveRemoteFile(LocalFileNameRemoteFileUrl)

dim language_arr()
language_arr() = "數據庫連接的參數設置錯誤!"
language_arr() = "數據庫連接的類型參數設置錯誤!"
language_arr() = "數據庫連接失敗!"
language_arr() = "非法的參數值!"
language_arr() = "參數值不是有效的日期格式!"
language_arr() = "操作失敗!"
language_arr() = "欄目有重名!"
language_arr() = "欄目名稱為空!"
language_arr() = "欄目文件夾創建失敗!"
language_arr() = "您沒有此權限!"

函數ID
函數作用建立數據庫的連接
修改時間
傳人參數
connectStr數據庫連接字符串
connectType數據庫類別數字型為Access為MS SQL
返回值

  sub ConnOpen(DataBaseConnectStrDBTypeConn_object)
Set Conn_object = ServerCreateobject("adodbconnection")
if DataBaseConnectStr = "" then call ShowErr(language_arr())
if DBType = then
Conn_objectOpen "driver={Microsoft Access Driver (*mdb)};dbq=" & DataBaseConnectStr
elseif DBType = then
Conn_objectOpen "Provider=SQLOLEDB;" & DataBaseConnectStr
else
call ShowErr(language_arr())
end if
errclear
end sub

  函數ID
函數作用斷開數據庫的連接
修改時間
傳人參數
返回值

  Sub ConnClose(Conn_object)
Conn_objectclose
set Conn_object = nothing
End sub

  函數ID
函數作用防止SQL注入
修改時間
傳人參數
paraName:參數名稱字符型
paraType:參數類型數字型(表示以上參數是數字表示以上參數為字符) 
返回值
過濾後的字符串

  Function SafeRequest(paraNameparaType)
dim paraValue
paraValue = Request(paraName)
select case paraType
case
paraValue = replace(paraValue"""[system:]")
paraValue = replace(paraValue"=""[system:]")
case
if not IsNumeric(paraValue) then call ShowErr(language_arr())
case
if not IsNumeric(paraValue) then call ShowErr(language_arr())
if paraValue = "" then paraValue =
case else
if len(paraValue) > paraType then call ShowErr(language_arr())
paraValue = replace(paraValue"""[system:]")
paraValue = replace(paraValue"=""[system:]")
end select
SafeRequest = paraValue
End function
===============================函數ID
函數作用格式化日期
修改時間
傳人參數
dateStr:日期字符串
paraType:日期類型數字型
返回值
格式化後的日期
Function DateFormat(dateStrdateType)
Dim dateString
if IsDate(dateStr) = False then
call ShowErr(language_arr())
end if
Select Case dateType
Case ""
dateString = Year(dateStr)&""&Month(dateStr)&""&Day(dateStr)
Case ""
dateString = Year(dateStr)&""&Month(dateStr)&""&Day(dateStr)
Case ""
dateString = Year(dateStr)&"/"&Month(dateStr)&"/"&Day(dateStr)
Case ""
dateString = Month(dateStr)&"/"&Day(dateStr)&"/"&Year(dateStr)
Case ""
dateString = Day(dateStr)&"/"&Month(dateStr)&"/"&Year(dateStr)
Case ""
dateString = Month(dateStr)&""&Day(dateStr)&""&Year(dateStr)
Case ""
dateString = Month(dateStr)&""&Day(dateStr)&""&Year(dateStr)
Case ""
dateString = Month(dateStr)&""&Day(dateStr)
Case ""
dateString = Month(dateStr)&"/"&Day(dateStr)
Case ""
dateString = Month(dateStr)&""&Day(dateStr)
Case ""
dateString = Month(dateStr)&language_arr()&Day(dateStr)&language_arr()
Case ""
dateString = Day(dateStr)&language_arr()&Hour(dateStr)&language_arr()
case ""
dateString = Day(dateStr)&language_arr()&Hour(dateStr)&language_arr()
Case ""
dateString = Hour(dateStr)&language_arr()&Minute(dateStr)&language_arr()
Case ""
dateString = Hour(dateStr)&":"&Minute(dateStr)
Case ""
dateString = Year(dateStr)&language_arr()&Month(dateStr)&language_arr()&Day(dateStr)&language_arr()
Case Else
dateString = dateStr
End Select
DateFormat = dateString
End Function

函數ID
函數作用顯示錯誤提示
修改時間
傳人參數

   errStr:錯誤提示字符型
返回值返回提交頁面

  sub ShowErr(errStr)
ResponseWrite("<script>alert("""&errStr&""");locationhref=""javascript:historyback()"";</script>")
ResponseEnd
End sub


From:http://tw.wingwit.com/Article/program/net/201311/14091.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.