ASP SQL anti-injection program [POST,QUERY,SQL]

Source: Internet
Author: User


<%

Dim Query_badword,form_badword,i,err_message,err_web,name

Err_message = 1 ' processing mode: 1 = hint information, 2 = Turn page, 3 = prompt before turning

Err_web = "err.asp" The page to turn when error

Query_badword= "' ∥AND∥SELECT∥UPDATE∥CHR∥DELETE∥%20FROM∥;∥INSERT∥MID∥MASTER.∥SET∥CHR (37) ∥="

' Define get illegal parameters in this section, use ' ∥ ' interval

Form_badword= "' ∥%∥&∥*∥#∥ (∥) ∥=" ' defines post illegal parameters in this section, using the "∥" interval
'
On Error Resume Next

'-----Filter the Get query value.

If request. Querystring<> "" Then
Chk_badword=split (Query_badword, "∥")
For each query_name in Request.QueryString
For i=0 to UBound (Chk_badword)
If Instr (LCase, request. QueryString (Query_name)), Chk_badword (i)) <>0 Then
Select Case Err_message
Case "1"
Response.Write "<script Language=javascript>alert" (' Pass parameter Error! The value of the parameter ' &name& ' contains an illegal string! nn please do not appear in the parameter: and update delete; Insert the illegal characters such as Mid master! '); Window.close ();</script> "
Case "2"
Response.Write "<script language=javascript>location.href= '" &Err_Web& "' </Script>"
Case "3"
Response.Write "<script Language=javascript>alert" (' Pass parameter Error! The value of the parameter ' &name& ' contains an illegal string! nn please do not appear in the parameter: and update delete; Insert the illegal characters such as Mid master! Location.href= ' "&Err_Web&" ';</script> "
End Select
Response.End
End If
NEXT
NEXT
End If

'-----Filter the Post form values.

If request.form<> "then
Chk_badword=split (Form_badword," ∥ ")
for each name in Request.Form
for i=0 t O UBound (chk_badword)
If Instr (LCase (Request.Form (name), Chk_badword (i)) <>0 Then
Select case Err_ Message
  Case "1"
Response.Write "<script language=javascript>alert (' Wrong! The value of the form ' &name& ' contains an illegal string! nn please do not appear in the form:% & * # () and other illegal characters! '); Window.close ();</script> "
  case" 2 "
Response.Write" <script language=javascript> Location.href= ' "&Err_Web&" ' </Script> "
  Case" 3 "
Response.Write" <script language= Javascript>alert (' a mistake! The value of the parameter ' &name& ' contains an illegal string! nn please do not appear in the form:% & * # ()   Such illegal characters! '); location.href= ' &Err_Web& ';</script> '
End Select
Response.End
End If
Next
Next
End If
%>

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.