ASP prevents SQL Injection code

Source: Internet
Author: User

Set the following Code Copy to the header of each file to prevent SQL injection. Program Security is the most important :)

<%
Dim fy_url, fy_a, fy_x, fy_cs (), fy_cl, fy_ts, fy_zx
'--- Define partial headers ------
Fy_cl = 1' Processing Method: 1 = prompt message, 2 = redirect page, 3 = Prompt before redirect
Fy_zx = "error. asp" 'page to be switched when an error occurs
'--- Define the end of part ------

On Error resume next
Fy_url = request. servervariables ("QUERY_STRING ")
Fy_a = Split (fy_url ,"&")
Redim fy_cs (ubound (fy_a ))
On Error resume next
For fy_x = 0 to ubound (fy_a)
Fy_cs (fy_x) = left (fy_a (fy_x), instr (fy_a (fy_x), "=")-1)
Next
For fy_x = 0 to ubound (fy_cs)
If fy_cs (fy_x) <> "" then
If instr (lcase (Request (fy_cs (fy_x), "'") <> 0 or instr (lcase (Request (fy_cs (fy_x), "and ") <> 0 or instr (lcase (Request (fy_cs (fy_x), "select") <> 0 or instr (lcase (Request (fy_cs (fy_x ))), "Update") <> 0 or instr (lcase (Request (fy_cs (fy_x), "CHR ") <> 0 or instr (lcase (Request (fy_cs (fy_x), "Delete % 20 from ") <> 0 or instr (lcase (Request (fy_cs (fy_x), ";") <> 0 or instr (lcase (Request (fy_cs (fy_x ))), "insert") <> 0 or instr (lcase (Request (fy_cs (fy_x), "mid ") <> 0 or instr (lcase (Request (fy_cs (fy_x), "Master. ") <> 0 then
Select case fy_cl
Case "1"
Response. Write "<script language = JavaScript> alert ('error! The value of the parameter "& fy_cs (fy_x) &" contains an invalid string! \ N do not contain invalid characters such as;, and, select, update, insert, delete, and CHR in the parameter! \ N what do you want! Don't be bored! Thank you! '); Window. Close (); </SCRIPT>"
Case "2"
Response. Write "<script language = JavaScript> location. href = '" & fy_zx & "' </SCRIPT>"
Case "3"
Response. Write "<script language = JavaScript> alert ('error! The value of the parameter "& fy_cs (fy_x) &" contains an invalid string! \ N do not contain invalid characters such as;, and, select, update, insert, delete, and CHR in the parameter! \ N what do you want! Don't be bored! Thank you! '); Location. href =' "& fy_zx &" '; </SCRIPT>"
End select
Response. End
End if
End if
Next
%>

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.