Page 1 of 1

What's the truth about runtime enable/disable of magic_quote

Posted: Wed Sep 12, 2007 12:11 pm
by ssmela
I am running PHP Version 5.2.2 on a Windows PC using XAMPP. I created the following code:

Code: Select all

<?php 
   ini_set('magic_quotes_gpc', 'On');
   echo("magic_quotes_gpc=".get_magic_quotes_gpc()."<br />");
   ini_set('magic_quotes_gpc', 'Off');
   echo("magic_quotes_gpc=".get_magic_quotes_gpc()."<br />");
?>
I get the following result:

magic_quotes_gpc=1
magic_quotes_gpc=1


I have read conflicting information about whether it is possible to change get_magic_quotes_gpc at runtime.

Can someone please clear this up?

Thank you,

Sam Mela

Posted: Wed Sep 12, 2007 12:21 pm
by John Cartwright
Some settings you cannot use ini_set(), because the code has already been interpreted. You can use .htaccess

Code: Select all

php_flag magic_quotes_gpc on
.. to disable magic quotes

Posted: Wed Sep 12, 2007 1:11 pm
by ssmela
Thank you, but I am unclear what has already been "interpreted".

Can you please explain?

Posted: Wed Sep 12, 2007 1:37 pm
by dull1554
thats one var. that is intrepreted before any php script is read by the interpreter because depending on how that is set it will intrepret the code differently.....i think

Posted: Wed Sep 12, 2007 2:52 pm
by kaszu
Magic quotes affects GET POST and COOKIE global arrays. These arrays are 'created' by PHP, before it starts to interpet your script so you could use them.
That's why changing magic_quotes_gpc from On to Off (and otherwise) won't have any effect and PHP team decided to disable possibility to change this value as it won't have any effect.
As it has already been said to change magic_quotes_gpc you need to do it before PHP starts interpeting your script.

Posted: Wed Sep 12, 2007 3:34 pm
by ssmela
Makes perfect sense. Thank you very much.

Sam Mela