The common custom Function Encyclopedia of ASP

Source: Internet
Author: User
Tags dateformat sql injection

<%

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

' function list:
' 1: Establish a connection to the database Connopen (databaseconnectstr,dbtype,conn_object)
' 2: Disconnect the database Connclose (conn_object)
' 3: Prevent SQL injection Saferequest (paraname,paratype)
' 4: Format date DateFormat (datestr,datetype)
' 5: Display error hint Showerr ( ERRSTR)
' 6: Specific data in query string Selectstr (contentstr,patternstr,patternnum)
' 7: Filter specified character Leach (contentstr,badwords)
' 8: Remote file content crawl seize (urlstr)
' 9: Data stream encoding processing bytestobstr (body,cset)
' 10: Encoding Cookies Codecookie (CONTENTSTR)
' 11: Decode Cookies Decodecookie (CONTENTSTR)
' 12: Verify that the data submission source is legitimate chkpost ()
' 13: Personalized encryption Myencrypt (strpassword)
' 14: Prohibit browser caching this page nobuffer ()
' 15: Web page formatted input text HTMLEncode (fstring)
' 16: The specified length of the intercept string from the head (by number of characters) Gottopic (Str,strlen)
' 17: Detect authentication Code Checkradompass (radompass)
' 18: Generate Authenticode Code getcode ()
' 19: Get client operating system version Getsystem ()
' 20: Database transaction processing Connmanage (Conn_object)
' 21: Quick sort (recursive) QuickSort (arr,low,high)
' 22: Add the elements of an array to a specific string Arr_join (arr,character)
' 23: Number of strings separated by a delimiter Count_character (str,character)
' 24: Intercepting a specified number in a string containing a separatorString Inter_str_by_character_num (Str,character,start,num)
' 25: Download file with Stream DownloadFile (strfile)
' 26: Return information Send_back (resultwords)
' 27: Get error message Get_err ()
' 28: Opposite Saferequest saferesponse (content)
' 29: Save remote picture Saveremotefile (localfilename,remotefileurl)
' 30: ...
Dim Language_arr
Language_arr (0) = "Database connection parameter setting error!" "
Language_arr (1) =" Database connection type parameter setting Error! "
Language_arr (2) =" Database connection Failed! "
Language_arr (3) =" Invalid parameter value! "
Language_arr (4) =" parameter value is not a valid date format! "
Language_arr (5) =" Operation failed! "
Language_arr (6) =" column has duplicate name! "
Language_arr (7) =" Column name is empty! "
Language_arr (8) =" Column folder creation failed! "
Language_arr (9) =" You do not have this permission! The
'
function id:1
Function: Establishing a connection to the database
' Modify time:
' descendant parameters:
' connectstr: Database connection string
' Connecttype: Database category-Number font, 0 is access,1 for MS SQL
return value:
'

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)};d bq=" & Databaseconnectstr
ElseIf DBType = 1 Then
Conn_object. Open "Provider=SQLOLEDB.1;" & Databaseconnectstr
Else
Call Showerr (Language_arr (1))
End If
Err.Clear
End Sub
'

' Function id:2
' Function: Disconnect the database
' Modify Time:
' Descendant parameters:
' Return value:
'

Sub Connclose (Conn_object)
Conn_object.close
Set conn_object = Nothing
End Sub
'

' Function Id:3
' Function action: Prevent SQL injection
' Modify Time:
' Descendant parameters:
' Paraname: Parameter name-character type
' Paratype: Parameter Type-numeric (1 indicates that the above parameter is a number, and 0 indicates that the above parameter is a character)
' Return value:
' The filtered string
'

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) &gt; Paratype then call Showerr (Language_arr (3))


paravalue = replace (Paravalue, "'", "[system:34]")


paravalue = replace (paravalue, "=", "[system:61]")


End Select


saferequest = Paravalue


End Function


' =============================== ' function Id:4


' function: Format Date


' Modify time:


' descendants parameter:


' datestr: Date string


' paratype: Date type-Digital


' return value:


' formatted date


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) &amp; "-" &amp;month (DATESTR) &amp; "-" &amp;day (DATESTR)


case "2"


datestring = year (DATESTR) &amp; "." &amp;month (DATESTR) &amp; "." &amp;day (DATESTR)


case "3"


datestring = year (DATESTR) &amp; "/" &amp;month (DATESTR) &amp; "/" &amp;day (DATESTR)


case "4"


datestring = Month (DATESTR) &amp; "/" &amp;day (DATESTR) &amp; "/" &amp;year (DATESTR)


case "5"


datestring = Day (DATESTR) &amp; "/" &amp;month (DATESTR) &amp; "/" &amp;year (DATESTR)


case "6"


datestring = Month (DATESTR) &amp; "-" &amp;day (DATESTR) &amp; "-" &amp;year (DATESTR)


case "7"


datestring = Month (datestr) &amp; "." &amp;day (DATESTR) &amp; "." &amp;year (DATESTR)


case "8"


datestring = Month (DATESTR) &amp; "-" &amp;day (DATESTR)


case "9"


datestring = Month (DATESTR) &amp; "/" &amp;day (DATESTR)


case "10"


datestring = Month (datestr) &amp; "." &amp;day (DATESTR)


case "11"


datestring = Month (DATESTR) &amp;language_arr (6) &amp;day (DATESTR) &amp;language_arr (7)


case "12"


datestring = Day (datestr) &amp;language_arr (7) &amp;hour (DATESTR) &amp;language_arr (8)


case "13"


datestring = Day (datestr) &amp;language_arr (7) &amp;hour (DATESTR) &amp;language_arr (8)


case "14"


datestring = Hour (DATESTR) &amp;language_arr (8) &amp;minute (DATESTR) &amp;language_arr (9)


case "15"


datestring = Hour (datestr) &amp; ":" &amp;minute (DATESTR)


case "16"


datestring = year (DATESTR) &amp;language_arr (5) &amp;month (DATESTR) &amp;language_arr (6) &amp;day (DATESTR) &amp; Language_arr (7)


Case Else


datestring = Datestr


End Select


DateFormat = datestring


End Function


'


' function Id:5


' function: Display error hint


' Modify time:


' descendants parameter:

' ERRSTR: Error hint-character type
' Return value: Return to submit page
'

Sub Showerr (ERRSTR)
Response.Write ("<script>alert" "" &errStr& "" "); location.href=" "Javascript:history.back ()" "; </ Script> ")
Response.End
End Sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.