Home >Backend Development >PHP Problem >How to turn off magic quotes in php

How to turn off magic quotes in php

青灯夜游
青灯夜游Original
2021-02-20 14:14:202087browse

Close method: Set the magic_quotes_gpc, magic_quotes_runtime, magic_quotes_sybase options to Off in php.ini; or turn off the magic_quotes_gpc directive in ".htaccess".

How to turn off magic quotes in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php close magic quotes Method:

1. Turn off magic quotes on the server side

The following is a way to set these options to Off through the php.ini file example.

; Magic quotes
;

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

If you cannot modify the server-side configuration file, you can also use .htaccess. The example is as follows:

php_flag magic_quotes_gpc Off

[Recommended learning: "PHP Video Tutorial"]

2. Turn off magic quotes at runtime

<?php
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map(&#39;stripslashes_deep&#39;, $value) :
                    stripslashes($value);

        return $value;
    }

    $_POST = array_map(&#39;stripslashes_deep&#39;, $_POST);
    $_GET = array_map(&#39;stripslashes_deep&#39;, $_GET);
    $_COOKIE = array_map(&#39;stripslashes_deep&#39;, $_COOKIE);
    $_REQUEST = array_map(&#39;stripslashes_deep&#39;, $_REQUEST);
}
?>

But this is relatively inefficient, and it is better to modify the configuration appropriately.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of How to turn off magic quotes in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn