How to turn off php magic quotes?

青灯夜游
Release: 2023-03-04 15:40:02
Original
2678 people have browsed it

How to turn off php magic quotes: Set the "magic_quotes_gpc", "magic_quotes_runtime", and "magic_quotes_sybase" options to "Off" in the PHP configuration file php.ini.

How to turn off php magic quotes?

Recommended: "PHP Video Tutorial"

PHP Close Magic Quotes

1. Modify the PHP configuration file php.ini

This method is only suitable when you have the right to manage the server. If you use a virtual space, you can only use the last two method.

Set magic_quotes_gpc, magic_quotes_runtime, and magic_quotes_sybase all to off in the PHP configuration file php.ini.

As shown below:

magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off
Copy after login

2. Using .htaccess file

This method is only supported when the server supports htaccess, and most current servers generally support it

Add the following sentence to the .htaccess file in the program directory:

php_flag magic_quotes_gpc Off
Copy after login

3. Shield in the code

This method is the most portable and does not need to consider the server configuration. It can be used if it supports PHP.

Add the following code at the beginning of all PHP files

if(get_magic_quotes_gpc()){ function stripslashes_deep($value){ $value=is_array($value)?array_map('stripslashes_deep',$value):stripslashes($value); return $value; } $_POST=array_map('stripslashes_deep',$_POST); $_GET=array_map('stripslashes_deep',$_GET); $_COOKIE=array_map('stripslashes_deep',$_COOKIE); $_REQUEST=array_map('stripslashes_deep',$_REQUEST); }
Copy after login

For more related programming knowledge, please visit:Programming Learning Website! !

The above is the detailed content of How to turn off php magic quotes?. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!