Set_magic_quotes_runtime and SET_MAGIC_QUOTES_GPC functions explain __ functions

Source: Internet
Author: User
Set_magic_quotes_runtime (0);

You can modify the settings of the Magic_quotes_runtime Boolean in php.ini

When your data has some
\
"
'
Such characters are useful when they are written to the database and are not filtered out, and are preceded by the

China's vast territory "haha"
China is a vast country, "haha"

Set_magic_quotes_runtime is the variable magic_quotes_runtime value that is used to set the configuration of the PHP environment.
0-Close 1-open

The detection state in the program with Get_magic_quotes_runtime, return 0 means to turn off this function, return 1 means this feature is turned on. If the magic_quotes_runtime is open, all externally introduced database data or files will automatically be converted into data containing backslash overflow characters.

In the php.ini configuration file, there is a Boolean setting that is Magic_quotes_runtime, and when it is turned on, most PHP functions automatically add backslashes to the overflow characters from externally introduced (including database or file) data.

Of course, if you repeat the overflow character alphanumeric backslash, then there will be multiple backslashes in the string, so you should use Set_magic_quotes_runtime () and Get_magic_quotes_runtime () Sets and detects Magic_quotes_runtime status in php.ini files.

To make your program work regardless of what the server is set to do. You can use Get_magic_quotes_runtime to detect settings in the program. Fall decides whether you want to manually process it, or turn it off with Set_magic_quotes_runtime (0) when you start (or do not need to escape automatically).


MAGIC_QUOTES_GPC sets whether the ' "\ Plus backslash is automatically added to the data from the GPC (Get,post,cookie). You can use GET_MAGIC_QUOTES_GPC () to detect system settings. If this setting is not turned on, you can use the Addslashes () function to add,Its function is to the database query statements such as the need to add a backslash before some characters. These characters are single quotes ('), double quotes ("), backslashes (\) and NUL (NULL characters).


Magic Reference function The difference and usage of MAGIC_QUOTES_GPC and Magic_quotes_runtime PHP offers two handy magic reference functions for reference data MAGIC_QUOTES_GPC and Magic_quotes_runtime, These two functions, if the php.ini is set to ON, we will quote the data to encounter single quotes ' and double quotes ' and backslash \ When the automatic plus backslash, help us automatically translate symbols to ensure that the data operation of the correct operation, but we in different versions of PHP or different server configuration, some MAGIC_QUOTES_GPC and Magic_quotes_runtime are set to ON, and some are off, so the program we write must conform to on and off two of cases. So what's the difference between MAGIC_QUOTES_GPC and magic_quotes_runtime two functions? Look at the following description:

Magic_quotes_gpc
Scope of Action: Web customer service side;
Action time: The request starts with, for example, when the script is run.

Magic_quotes_runtime
Scope: Data read from a file or executed as a result of exec () or obtained from a SQL query;
Action time: The data that is generated each time the script accesses the running state.

So The set value of the MAGIC_QUOTES_GPC will affect the set value of the data magic_quotes_runtime obtained through get/post/cookies will affect the data read from the file or query from the database
Example Description:
$data 1 = $_post[' aaa '];

$data 2 = implode (file (' 1.txt '));

if (GET_MAGIC_QUOTES_GPC ()) {
Writes data $data1 directly to the database (automatic translation)
}else{
$data 1 = addslashes ($data 1);
Writes the data $data1 to the database, uses the function (Addslashes () to translate)
}

if (Get_magic_quotes_runtime ()) {
Writes data $data2 directly to the database (automatic translation)
// data read from the database after a stripslashes () output stripslashes () The function is to remove: \, and Addslashes () the opposite effect
}else{
$data 2 = addslashes ($data 2);
Write data $data2 to the database


Direct output of data read from a database
}
The key difference is the 2 points mentioned above: they target different processing objects
The set value of the MAGIC_QUOTES_GPC will affect the set value of the data magic_quotes_runtime obtained through get/post/cookies will affect the data read from the file or query from the database
Here's a couple of functions you'd like to associate:


Set_magic_quotes_runtime ():
Sets the Magic_quotes_runtime value. 0= closed. 1= Open. The default state is turned off. Can pass Echo phpinfo (); View Magic_quotes_runtime
GET_MAGIC_QUOTES_GPC ():
View the MAGIC_QUOTES_GPC value. 0= closed. 1= Open

Get_magic_quotes_runtime ():
View the Magic_quotes_runtime value. 0= closed. 1= Open.
Note that there is no set_magic_quotes_gpc () function, that is, you cannot set the value of MAGIC_QUOTES_GPC in the program.

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.