Gets the PHP environment variable MAGIC_QUOTES_GPC value, belongs to the PHP system function. Syntax: Long get_magic_quotes_gpc (void); return value: Length integerwhat does this function do? This function obtains the PHP environment configuration variable MAGIC_QUOTES_GPC (GPC, Get/post/cookie) value. Returns 0 to turn off this function; return 1 indicates that this function is turned on. When MAGIC_QUOTES_GPC is turned on, all ' (single quotes), "(double quotes), (backslash) and null characters are automatically converted to overflow characters that contain backslashes. In the PHP configuration file, there is a Boolean setting, which is magic_quotes_runtime. When it is opened, most of PHP's functions automatically add backslashes to the overflow characters in the data (including database or file) that are introduced externally. Of course, if you repeat the multibyte backslash for the overflow character, there will be multiple backslashes in the string, so use Set_magic_quotes_runtime () and Get_magic_quotes_runtime (). Sets and detects the Magic_quotes_runtime status in the php.ini file. In order to make your own program regardless of the server is what settings can be performed normally. You can use Get_magic_quotes_runtime to detect the state of the setting at the beginning of the program to determine whether you want to handle it manually, or to turn off the setting with Set_magic_quotes_runtime (0) when you start (or do not need automatic escaping). MAGIC_QUOTES_GPC sets whether the ' "\ Plus backslashes in the data coming from GPC (Get,post,cookie) are automatically set. System settings can be detected with GET_MAGIC_QUOTES_GPC (). If you do not open this setting, you can use the Addslashes () function to add, which is the function of the database query statements and so on need to precede some characters with a backslash. These characters are single quotes ('), double quotation marks ("), backslashes (\), and NUL (the NULL character). The general usage is as follows: if (!GET_MAGIC_QUOTES_GPC ()) {addslashes ($prot);} In the manual, when string addslashes (String str) is introduced, there is a sentence explaining the use and role of GET_MAGIC_QUOTES_GPC. By default, PHP instruction MAGIC_QUOTES_GPC is on, and it is primarily for all GET, POST, and COOKIE data automatically run Addslashes (). Do not use Addslashes () for strings that have been MAGIC_QUOTES_GPC escaped, because this results in double-layer escaping. You can use the function get_ when you encounter this situationMAGIC_QUOTES_GPC () for testing. In fact, this function is to determine whether PHP automatically calls addslashes this function: MAGIC_GPC in the most Earth buying system
- !--? php
- define (' SYS_MAGICGPC ', GET_MAGIC_QUOTES_GPC ());
-
- $_post = MAGIC_GPC ($_post);
-
- function magic_gpc ($string) {
- if (SYS_MAGICGPC) {
- if (Is_array ($string)) {
- foreach ($string as $key = $val) {
- $string [$key] = MAGIC_GPC ($val);
- }
- } else {
- $string = stripslashes ($string);
- }
- }
- return $string;
- }
-
- echo ' GET_MAGIC_QUOTES_GPC value: '. GET_MAGIC_QUOTES_GPC ();
- echo '
';
- Echo ' directly outputs the POST variable: '. $_post[' nowamagic '];
- echo '
';
- Echo ' is processed by MAGIC_GPC: '. MAGIC_GPC ($_post[' nowamagic ');
- ?
-
-
-
-
-
-
-
Copy Code Program output: GET_MAGIC_QUOTES_GPC value: 1 Direct output post variable: No ' wamagic.net processed by MAGIC_GPC: No ' wamagic.netOne more example:
-
- Echo ' GET_MAGIC_QUOTES_GPC: '. GET_MAGIC_QUOTES_GPC ();
- Echo '
';
- echo ' Direct output POST variable: '. $_post[' nowamagic '];
- Echo '
';
- Echo ' addslashes: '. Addslashes ($_post[' nowamagic ');
- if (!GET_MAGIC_QUOTES_GPC ()) {
- $nowamagic = addslashes ($_post[' nowamagic ');
- }
- else {
- $nowamagic = $_post[' nowamagic ');
- }
- Echo '
';
- echo ' Processed output: '. $nowamagic;
- ?>
-
Copy Code Program output: Get_magic_quotes_gpc:1 Direct output post variable: No ' wa\magic.netaddslashes:no\ ' wa\\magic.net after processing output: No ' wa\magic.net
|