Boolget_magic_quotes_gpc (void) returns the settings of the current magic_quotes_gpc configuration option. Remember that setting magic_quotes_gpc at runtime will not take effect. Bool get_magic_quotes_gpc (void) returns the settings of the current magic_quotes_gpc configuration option. Remember that setting magic_quotes_gpc at runtime will not take effect.
Script ec (2); script
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.
Example
1. addslashes () Example
The Code is as follows: |
|
$ Str = "Is your name O 'Reilly? "; // Output: Is your name O ''' reilly? Echo addslashes ($ str ); ?> |
Return Value
If you disable magic_quotes_gpc, 0 is returned; otherwise, 1 is returned. FALSE will be returned from PHP 5.4.O.
Example
The Code is as follows: |
|
// If magic quotes are enabled Echo $ _ POST ['lastname']; // O' reilly Echo addslashes ($ _ POST ['lastname']); // O \ 'Reilly // Applicable to various PHP versions If (get_magic_quotes_gpc ()){ $ Lastname = stripslashes ($ _ POST ['lastname']); } Else { $ Lastname = $ _ POST ['lastname']; } // If you use MySQL $ Lastname = mysql_real_escape_string ($ lastname ); Echo $ lastname; // O 'Reilly $ SQL = "INSERT INTO lastnames (lastname) VALUES ('$ lastname ')"; ?> |
Php. ini: get_magic_quotes_gpc
In the php configuration file, a Boolean value is set to magic_quotes_runtime. When it is enabled,
Most php functions automatically add reverse characters to overflow characters in external imported data (including databases or files ).
Slash. Of course, if you repeatedly Add a backslash to the overflow character, there will be multiple backlash in the string.
Use set_magic_quotes_runtime () and get_magic_quotes_runtime () to set and detect php. ini.
File magic_quotes_runtime status. In order to make your programs work normally regardless of the server settings
Run. You can use get_magic_quotes_runtime to check the status of the setting and decide 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: Set whether to automatically add backslashes to '"\ in the data sent by GPC (get, post, cookie ).
Line. You can use get_magic_quotes_gpc () to detect system settings. If this setting is not enabled, you can use
The addslashes () function is added to the database query statement and so on.
Slash. These characters are single quotation marks ('), double quotation marks ("), backslash (\), and NUL (NULL ).