Quickly understand the principle of escaping PHP quotes. In PHP, we have three settings for automatic transfer of (single quotation marks), (double quotation marks), (backslash), and NULL characters. PHP calls it magic quotes. we are using these three settings.
PHP has three settings for automatic transfer of '(single quotation marks),' (double quotation marks), (backslash), and NULL characters.
PHP calls it magic quotes. these three settings are
Magic_quotes_gpc
Affects HTTP request data (GET, POST, and COOKIE ). It cannot be changed at runtime. In PHP, the default value is on.
Magic_quotes_runtime
If it is enabled, most of the functions that retrieve data from external sources and return data, including the database and text files, will be escaped by the backslash. This option can be changed at runtime. the default value in PHP is off.
Magic_quotes_sybase
If it is enabled, the single quotation marks are used to escape the single quotation marks in PHP, rather than the backslash. This option will completely overwrite magic_quotes_gpc. If two options are enabled at the same time, the single quotation marks will be converted ". Double quotation marks, backslash, and NULL characters are not escaped.
Although it is convenient to implement automatic PHP quotation mark escape for special characters, this will reduce the program efficiency and cause the program to be transplanted into trouble. If you do not know the settings of the server ini, you need to call get_magic_quotes_gpc (), get_magic_quotes_runtime () or ini_get () to check the status.
For example:
- if (!get_magic_quotes_gpc()) {
- $lastname = addslashes
($_POST['lastname']);
- } else {
- $lastname = $_POST['lastname'];
- }
Therefore, it is best to disable the magic quotation marks of php and manually use addslashes () and stripslashes () to escape and cancel the escape of PHP quotation marks. You can learn about discuz and add set_magic_quotes_runtime (0); to the configuration file to cancel escape.
PHP has three settings for automatic (single quotation marks), (double quotation marks), (backslash), and NULL character transfer. PHP calls it magic quotes. these three settings are respectively...