First of let me say that Magic Quotes is deprected from the PHP 5.3 and will be removed completely from the PHP 6. But as a developer you might face a situation when you have to work on application which runs on older version of PHP with some older functionality like rely on Magic Quotes.
So let’s get into Magic Quotes in PHP.
Magic Quotes is the process which escape the incoming data to the PHP script like $_POST, $_GET. But it is recommeded to code with he magic quotes off.
When magic quotes is enabled then it will escape single quote(‘), Double Quote(“), backslash(\) and NULL by placing backslash in front of these characters. This is same as performing addslashes() on any string.
So whenever your user post the form with value like avinash’s name then you will get avinash\’s name in $_POST value.
There is no reason which shows any benefit for using Magic Quotes. Hence it is deprecated from PHP 5.3.0.
So it not a good practice to use the magic Quotes then how to disable this? Let’s have a look at below section.
There ae several ways to disable the Magic Quotes.
You can set below setting from php.ini file.
Place below code in your .htaccess file if you don’t have access to php.ini file.
Sometimes disabling magic quotes through .htaccess will not affect. In that case you can have below code in top of all php code. So below code will remove shashes added by Magic Quotes.
Note: Magic Quotes is Deprected in PHP 5.3.0 and will be removed from PHP 6.0
Avinash Zala currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.
View all posts by: Avinash