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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ssmela
Forum Newbie
Posts: 5
Joined: Mon Aug 20, 2007 8:44 pm

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

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
ssmela
Forum Newbie
Posts: 5
Joined: Mon Aug 20, 2007 8:44 pm

Post by ssmela »

Thank you, but I am unclear what has already been "interpreted".

Can you please explain?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post 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.
ssmela
Forum Newbie
Posts: 5
Joined: Mon Aug 20, 2007 8:44 pm

Post by ssmela »

Makes perfect sense. Thank you very much.

Sam Mela
Post Reply