The right way to prevent database attacks

Source: Internet
Author: User

<?PHPfunctionCheck_input ($value){//slash slash removalif(GET_MAGIC_QUOTES_GPC())  {  $value=stripslashes($value); }//if it's not a number, enclose it .if(!Is_numeric($value))  {  $value= "'".mysql_real_escape_string($value) . "‘"; }return $value;}$con=mysql_connect("localhost", "Hello", "321");if(!$con)  {   die(' Could not connect: '.Mysql_error()); }//Make secure SQL$user= Check_input ($_post[' User ']);$pwd= Check_input ($_post[' pwd ']);$sql= "SELECT * from users whereuser=$userand password=$pwd";mysql_query($sql);Mysql_close($con);?>

GET_MAGIC_QOUTES_GPC ():

When Magic_quotes_gpc=on, the function GET_MAGIC_QUOTES_GPC () returns 1

When Magic_quotes_gpc=off, the function get_magic_quotes_gpc () returns 0

The role of the MAGIC_QUOTES_GPC function in PHP is to determine the data that resolves user prompts, such as the following: Post, get, and cookie data to increase the escape character "\" to ensure that the data does not quote the program, especially the database language . Fatal error due to contamination caused by special characters.

Stripslashes (): Remove GET_MAGIC_QOUTES_GPC () escape.

The mysql_real_escape_string () function escapes special characters in strings used in SQL statements.

The following characters are affected:

    • \x00
    • \ n
    • \ r
    • \
    • "
    • \x1a

The right way to prevent database attacks

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.