PHP Magic Function Application detailed _php tutorial

Source: Internet
Author: User
PHP provides two magic reference functions to facilitate our reference data MAGIC_QUOTES_GPC and Magic_quotes_runtime, both of which will encounter single quotes ' and double quotes ' and backslashes for the data we reference if the php.ini is set to ON is automatically with a backslash, help us to automatically translate the symbol, to ensure the correct operation of data operations, but we have different versions of PHP or different server configuration, some MAGIC_QUOTES_GPC and magic_quotes_runtime set to ON, and some are off, So the program we write must conform to both on and off two cases. So what's the difference between the two functions of MAGIC_QUOTES_GPC and Magic_quotes_runtime? Look at the following instructions:

MAGIC_QUOTES_GPC

The scope of action is: Web customer service side;
Action time: The start of the request is, for example, when the script is running.

Magic_quotes_runtime

Scope: Data read from a file or executed by exec () or from a SQL query;
Action time: Data generated each time the script accesses the running state.

So the MAGIC_QUOTES_GPC setting will affect the data obtained through Get/post/cookies, and the Magic_quotes_runtime setting will affect the data read from the file or the data that is queried from the database.

Example Description:

<form action= "" method= "post" >str:<input type= "text" name= "STR" ><input type= "submit" > </form> <?php/* we fill in the form: ' "these Symbols, if the MAGIC_QUOTES_GPC is not turned on, then they will not be escaped by a backslash */echo ' now the value passed through POST is: ', $_post[' str '], ' <br/> '; if (GET_MAGIC_QUOTES_GPC () {//Check if MAGIC_QUOTES_GPC is open, escape with addslashes if not open $str = $_post[' str '];} else {$str = addslashes ($_post[' str ');} Echo ' Here is escaped: ', $str, ' 

http://www.bkjia.com/PHPjc/446683.html www.bkjia.com true http://www.bkjia.com/PHPjc/446683.html techarticle PHP provides two magic reference functions to facilitate our reference data MAGIC_QUOTES_GPC and magic_quotes_runtime, these two functions if the php.ini is set to ON, the number we reference ...

  • 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.