How to turn off magic quotes in php

青灯夜游
Release: 2023-03-08 07:12:02
Original
2027 people have browsed it

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
Copy after login

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
Copy after login

[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);
}
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template