Configure get_magic_quotes_gpc in php to prevent SQL injection usage

Source: Internet
Author: User

Configure get_magic_quotes_gpc in php to prevent SQL injection usage

Get_magic_quotes_gpc (); is to obtain the value of the php environment variable magic_quotes_gpc. If the value is 1, it indicates that the configuration is enabled; if it is 0, it indicates that the configuration is disabled!

  1. Get_magic_quotes_gpc (); the value is 1, indicating that it is enabled. Php automatically adds the Escape Character "" to the parameter values passed by POST, GET, and COOKIE to ensure the security of the data. This especially prevents SQL injection.

  2. Get_magic_quotes_gpc (); the value is 0, indicating that it is disabled. The php parser does not automatically add the Escape Character "" to the parameter values passed by POST, GET, or COOKIE. Then, the addslashes function is used to escape the parameter.

     

  • Get_magic_quotes_gpc (); Disabled. Use the addslashes function to filter parameters to prevent injection. Example:

    <? Php

    $ Str = $ _ POST ['str'];

    If (! Get_magic_quotes_gpc () {// first, judge whether the function is enabled.

    $ NewStr = addslashes ($ str); // use the addslashes function to filter

    }

    ?>

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.