You are here:Home»KB»Programming»PHP»Disable Magic Quotes in a PHP script
Sunday, 06 May 2012 00:00

Disable Magic Quotes in a PHP script

Written by

Magic quotes are the bain opf any programmers life. If you commit something to a my sql database that has unescaped characters, php by default will escape them with a backslash '/' and this can mess all your code up.

The following shows you how you can detect if magic quotes are running and how to disable them.


Detect if magic quotes are running

Run this php code on your web server

<?php
if(get_magic_quotes_gpc())
	echo "Magic quotes are enabled";
else
	echo "Magic quotes are disabled";
?>

Disable magic quotes

If you alter the following code in your php.ini will disable magic quotes. You might als be able to use a php variable declaration but this will be less permanent.

; 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

 

Read 777 times Last modified on Sunday, 22 February 2015 20:04