Obtain the value of the PHP environment variable magic_quotes_gpc, which is a function of the PHP System. Syntax: long get_magic_quotes_gpc (void ); Return value: long integer What does this function do?This function gets the magic_quotes_gpc (GPC, Get/Post/Cookie) value of the variable configured in the PHP environment. If 0 is returned, this function is disabled. if 1 is returned, this function is enabled. When magic_quotes_gpc is enabled, all '(single quotation marks),' (double quotation marks), (backslash) and null characters are automatically converted to overflow characters containing the backslash. In the php configuration file, a Boolean value is set to magic_quotes_runtime. When it is enabled, most php functions automatically add backslashes to overflow characters in external imported (including database or file) data. Of course, if you repeatedly add a backslash to the overflow character, there will be multiple backlash in the string, so you need to use set_magic_quotes_runtime () and get_magic_quotes_runtime () to set and detect php. the magic_quotes_runtime status in the INI file. In order to make your programs run normally regardless of the server settings. You can use get_magic_quotes_runtime to check the status of the setting and determine whether to manually process it. or, you can use set_magic_quotes_runtime (0) to disable the setting at the beginning (or when automatic escape is not required. Magic_quotes_gpc: determines whether to automatically add a backslash to '"\ in the data sent by GPC (get, post, cookie. You can use get_magic_quotes_gpc () to detect system settings. If this setting is not enabled, you can use the addslashes () function to add backslashes before certain characters for database query statements. These characters are single quotation marks ('), double quotation marks ("), backslash (\), and NUL (NULL ). The general usage is as follows: If (! Get_magic_quotes_gpc () {addslashes ($ prot );}In the manual, the string addslashes (string str) describes the usage and function of get_magic_quotes_gpc. By default, the PHP command magic_quotes_gpc is on, which automatically runs addslashes () on all GET, POST, and COOKIE data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection. In fact, this function is used to determine whether PHP automatically calls the addslashes function: Magic_gpc in the most popular group buying system
-
- 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 output the POST variable: '. $ _ POST ['nowamagic'];
- Echo'
';
- Echo 'processed by magic_gpc:'. magic_gpc ($ _ POST ['nowamagic ']);
- ?>
-
-
-
-
Program output: Value of get_magic_quotes_gpc: 1 The POST variable: no 'wamagic. net is directly output by magic_gpc: no 'wamagic. netAnother example:
-
- Echo 'get _ magic_quotes_gpc: '. get_magic_quotes_gpc ();
- Echo'
';
- Echo 'directly output the 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 'output after processing: '. $ nowamagic;
- ?>
-
-
-
-
Program output: Get_magic_quotes_gpc: 1 directly outputs the POST variable: no 'wa \ magic. netaddslashes: no \ 'wa \ magic.net after processing. output: no 'wa \ magic.net
|