Code to prevent SQL injection attacks _ PHP Tutorial

Source: Internet
Author: User
Code used to prevent SQL injection attacks. SQL injection attacks use designed vulnerabilities to run SQL commands on the target server and perform other attacks, when SQL commands are dynamically generated, the number of SQL injection attacks that are not input to users are exploited to run SQL commands on the target server and perform other attacks by exploiting design vulnerabilities, the failure to verify the data entered by the user during dynamic generation of SQL commands is the main cause of the successful SQL injection attacks. For example:
If your query statement is select * from admin where username = '"& user &"' and password = '"& pwd &"'"
Then, if my user name is: 1 'or '1' = '1
Then, your query statement will become:
Select * from admin where username = '1 or '1' = '1' and password = '"& pwd &"'"
In this way, your query statements are passed and you can access your management interface.
Therefore, you need to check user input for defense purposes. Special characters, such as single quotes, double quotation marks, semicolons, commas, colons, and connection numbers, are converted or filtered.
Special characters and strings to be filtered include:
Net user
Xp_mongoshell
/Add
Exec master. dbo. xp_mongoshell
Net localgroup administrators
Select
Count
Asc
Char
Mid
'
:
"
Insert
Delete from
Drop table
Update
Truncate
From
%
Below are two types of code I have written to prevent injection attacks for your reference!
Code for preventing SQL injection attacks in js version ~ :
[Code start]

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.