Home > Backend Development > PHP Tutorial > PHP - Magic Quotes simple tutorial_PHP tutorial

PHP - Magic Quotes simple tutorial_PHP tutorial

WBOY
Release: 2016-07-20 11:00:45
Original
1075 people have browsed it

Magic Quotes is used to filter illegal information submitted through the form. if(get_magic_quotes_gpc()) echo "Magic quotes are enabled"; else echo "Magic quotes are disabled"; ​

PHP-magic quotes
Prior to PHP 6 there was a feature called magic quotes created to help protect novice programmers from writing bad table processing code. Magic quotes will automatically escape dangerous form data that could be used for SQL injection with backslashes. The characters escaped by PHP include: quote ' , double quote " , backslash and NULL characters.

AdvertisingTizag.com
However, this newbie protection proved to cause more problems than it solved in PHP 6 instead. If your PHP version is any version before 6 then you should use this lesson to understand how magic quotes may affect you.

magic quotes-do they make?
First thing first, you need to check if you have magic quotes enabled on your server. The get_magic_quotes_gpc function will return 0 (off) or 1 (on). These boolean values ​​make for a good statement if 1 is true and 0 is false.

if(get_magic_quotes_gpc())
echo "Magic quotes are enabled";
else
echo "Magic quotes are disabled";

The output depends on whether your php is enabled

magic quotes in action
It is now possible to make a simple form showing how the processor of a machine with magic quotes will enable characters who may escape danger. This form submits itself, so you only need to make a file, "magic quotes.php" to test it.

echo "Altered Text: ".$_POST['question'];
?>

Remove backslashes -s tripslashes() function
After using PHP's backslash clearing function stripslashes it's smart to add some magic quotes like our check for "Are they enabled?" in the above section. This way you won't accidentally remove slashes that are considered legal in the future if your PHP magic quotes settings change in the future.

echo "Removed Slashes: ";
// Remove those slashes
if(get_magic_quotes_gpc())
echo stripslashes($_POST['question']);
else
echo $_POST['question'];


?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445498.htmlTechArticleMagic Quotes is used to filter illegal information submitted by forms, if(get_magic_quotes_gpc()) echo Magic quotes are enabled;else echo Magic quotes are disabled; PHP-magic q...
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