<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Magic Quotes Headaches</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/</link>
	<description></description>
	<pubDate>Sun, 20 Jul 2008 21:08:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: phpdevel</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-615426</link>
		<dc:creator>phpdevel</dc:creator>
		<pubDate>Mon, 28 Jan 2008 22:42:07 +0000</pubDate>
		<guid isPermaLink="false">#comment-615426</guid>
		<description>A direct quote from PHP.net:
"An example use of stripslashes() is when the PHP directive magic_quotes_gpc  is on (it's on by default), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form."
 - http://us3.php.net/stripslashes

NOTICE: magic_quotes_gpc is on BY DEFAULT!!!!  A word of advice, do not make assumptions, check your PHP.ini using phpinfo() to determine your PHP configuration.  Site Admins aren't necessarily PHP pros, and therefore may not understand PHP directives, and unwittingly make alterations to a default PHP.ini.  As a developer every site is unique, look at this site, for example, they explicitly ask that you escape a post to this forum. (smart or not) security through obscurity?  Check your own input... don't assume yours will behave the same as Joe's or Eddie's because they said thats how theirs was set up, so thats how yours will be set up.  This is exactly my problem now, I was assuming my input was handled one way when in fact it was being handled another... didn't notice it until someone asked me about a formatting problem. oops (take my own advise)</description>
		<content:encoded><![CDATA[<p>A direct quote from PHP.net:<br />
&#8220;An example use of stripslashes() is when the PHP directive magic_quotes_gpc  is on (it&#8217;s on by default), and you aren&#8217;t inserting this data into a place (such as a database) that requires escaping. For example, if you&#8217;re simply outputting data straight from an HTML form.&#8221;<br />
 - <a href="http://us3.php.net/stripslashes" rel="nofollow">http://us3.php.net/stripslashes</a></p>
<p>NOTICE: magic_quotes_gpc is on BY DEFAULT!!!!  A word of advice, do not make assumptions, check your PHP.ini using phpinfo() to determine your PHP configuration.  Site Admins aren&#8217;t necessarily PHP pros, and therefore may not understand PHP directives, and unwittingly make alterations to a default PHP.ini.  As a developer every site is unique, look at this site, for example, they explicitly ask that you escape a post to this forum. (smart or not) security through obscurity?  Check your own input&#8230; don&#8217;t assume yours will behave the same as Joe&#8217;s or Eddie&#8217;s because they said thats how theirs was set up, so thats how yours will be set up.  This is exactly my problem now, I was assuming my input was handled one way when in fact it was being handled another&#8230; didn&#8217;t notice it until someone asked me about a formatting problem. oops (take my own advise)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: SoreGums</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-298202</link>
		<dc:creator>SoreGums</dc:creator>
		<pubDate>Mon, 09 Jul 2007 06:42:53 +0000</pubDate>
		<guid isPermaLink="false">#comment-298202</guid>
		<description>Man I've run into major problems with magic quotes, thanks to the comments above from Ren its all fixed!

Thanks...

Man I can't wait to get my head around JBoss Seam - I've always tried to not do anything in PHP but this project needed to be producing results straight away and I had no choice but to start using PHP :(</description>
		<content:encoded><![CDATA[<p>Man I&#8217;ve run into major problems with magic quotes, thanks to the comments above from Ren its all fixed!</p>
<p>Thanks&#8230;</p>
<p>Man I can&#8217;t wait to get my head around JBoss Seam - I&#8217;ve always tried to not do anything in PHP but this project needed to be producing results straight away and I had no choice but to start using PHP :(</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-212421</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Tue, 27 Mar 2007 07:19:25 +0000</pubDate>
		<guid isPermaLink="false">#comment-212421</guid>
		<description>PHP is one of the most incompetently designed languages ever. Sad but true.</description>
		<content:encoded><![CDATA[<p>PHP is one of the most incompetently designed languages ever. Sad but true.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-209036</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 22 Mar 2007 04:30:23 +0000</pubDate>
		<guid isPermaLink="false">#comment-209036</guid>
		<description>Stellar! Saved my ass, thanks for the stripslashes code.</description>
		<content:encoded><![CDATA[<p>Stellar! Saved my ass, thanks for the stripslashes code.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: NoOne</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-36475</link>
		<dc:creator>NoOne</dc:creator>
		<pubDate>Tue, 11 Jul 2006 04:19:50 +0000</pubDate>
		<guid isPermaLink="false">#comment-36475</guid>
		<description>From PHP Manual recursive stripslashes code:
&lt;code&gt;
if (get_magic_quotes_gpc()) {
   function stripslashes_deep($value)
   {
       $value = is_array($value) ?
                   array_map('stripslashes_deep', $value) :
                   stripslashes($value);

       return $value;
   }

   $_POST = array_map('stripslashes_deep', $_POST);
   $_GET = array_map('stripslashes_deep', $_GET);
   $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
&lt;/code&gt;

NoOne, </description>
		<content:encoded><![CDATA[<p>From PHP Manual recursive stripslashes code:<br />
<code>
if (get_magic_quotes_gpc()) {
   function stripslashes_deep($value)
   {
       $value = is_array($value) ?
                   array_map('stripslashes_deep', $value) :
                   stripslashes($value);

       return $value;
   }

   $_POST = array_map('stripslashes_deep', $_POST);
   $_GET = array_map('stripslashes_deep', $_GET);
   $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
</code></p>
<p>NoOne,</p>]]></content:encoded>
	</item>
	<item>
		<title>By: NoOne</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-36471</link>
		<dc:creator>NoOne</dc:creator>
		<pubDate>Tue, 11 Jul 2006 04:15:15 +0000</pubDate>
		<guid isPermaLink="false">#comment-36471</guid>
		<description>From PHP Manual recursive stripslashes code:
&lt;code&gt;&lt;/code&gt;

NoOne, </description>
		<content:encoded><![CDATA[<p>From PHP Manual recursive stripslashes code:<br />
<code></code></p>
<p>NoOne,</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-1921</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1921</guid>
		<description>&lt;p&gt;A little more in-depth treatment of this topic, including code to detect and reverse the effects of all three magic_quotes settings, can be found here:&lt;/p&gt;

&lt;p&gt;http://education.nyphp.org/phundamentals/PH_storingretrieving.php&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>A little more in-depth treatment of this topic, including code to detect and reverse the effects of all three magic_quotes settings, can be found here:</p>
<p><a href="http://education.nyphp.org/phundamentals/PH_storingretrieving.php" rel="nofollow">http://education.nyphp.org/phundamentals/PH_storingretrieving.php</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Knowles</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-1922</link>
		<dc:creator>Alan Knowles</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1922</guid>
		<description>&lt;p&gt;Yes Magic Quotes are evil :)&lt;br /&gt;
The example code introduces nighmares for using any library that may interact with input variables (which is not usually a good idea anyway).&lt;/p&gt;

&lt;p&gt;It's far better to add this to the start of the application, than even bothering trying to deal with them..&lt;br /&gt;
if (get_magic_quotes_gpc()) {&lt;br /&gt;
   trigger_error("Turn of magic quotes in php.ini / .htaccess or apache config", E_USER_ERROR);&lt;br /&gt;
} &lt;br /&gt;
&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Yes Magic Quotes are evil :)<br />
The example code introduces nighmares for using any library that may interact with input variables (which is not usually a good idea anyway).</p>
<p>It&#8217;s far better to add this to the start of the application, than even bothering trying to deal with them..<br />
if (get_magic_quotes_gpc()) {<br />
   trigger_error(&#8221;Turn of magic quotes in php.ini / .htaccess or apache config&#8221;, E_USER_ERROR);<br />
} </p>]]></content:encoded>
	</item>
	<item>
		<title>By: Skunk</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-1923</link>
		<dc:creator>Skunk</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1923</guid>
		<description>&lt;p&gt;The library thing is the killer as far as I'm concerned. Basically, the magic quotes issue makes it all but impossible to write code for other people to re-use (unless the code has no interactions at all with the outside world). If you write it expecting a specific setting for magic_quotes and the end user has a different setting you'll get horrible problems.&lt;/p&gt;

&lt;p&gt;Avoiding user input isn't a very pretty option either, since your library functions may be passed strings from input by the user which are in an "unknown" state - they might be escaped, they might not be. Alan's suggestion of dying if magic qutoes are on isn't a terrible idea, but if a user already has a large code base that expects the feature to be on they will be unable to use your library without a major rewrite (although maybe that's not a bad thing). That said, many users on shared hosting don't have access to php.ini OR htaccess files, and it's a little harsh expecting them to change hosts just to reuse your code.&lt;/p&gt;

&lt;p&gt;The most annoying thing about this all is that magic quotes is actually a very poor solution to the database escaping problem. Firstly, different databases have different escaping rules (I think SQL server requires quotes to be doubled up rather than backslash escaped). Secondly, a far, far more reliable way of safely escaping database variables used be pretty much databases access libraries for loads of other languages is to use something like this:&lt;/p&gt;

&lt;p&gt;$query = sql_query("select * from table where tag = ? and section = ?", $tag, $section);&lt;/p&gt;

&lt;p&gt;In magic quotes defence, if the above were used there would always be utterly clueless newbies who still stuck everything together using string concatenation and opened them up to vulnerabilities, but a decent sized warning against this on the manual page for the function would probably be enough to save all but the most hopeless of cases.&lt;/p&gt;

&lt;p&gt;This turned in to a bit of a rant, but magic quotes is one of the principle things that turned me away from PHP for large web application development (I use Python now) so it's something of a pet peeve!&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>The library thing is the killer as far as I&#8217;m concerned. Basically, the magic quotes issue makes it all but impossible to write code for other people to re-use (unless the code has no interactions at all with the outside world). If you write it expecting a specific setting for magic_quotes and the end user has a different setting you&#8217;ll get horrible problems.</p>
<p>Avoiding user input isn&#8217;t a very pretty option either, since your library functions may be passed strings from input by the user which are in an &#8220;unknown&#8221; state - they might be escaped, they might not be. Alan&#8217;s suggestion of dying if magic qutoes are on isn&#8217;t a terrible idea, but if a user already has a large code base that expects the feature to be on they will be unable to use your library without a major rewrite (although maybe that&#8217;s not a bad thing). That said, many users on shared hosting don&#8217;t have access to php.ini OR htaccess files, and it&#8217;s a little harsh expecting them to change hosts just to reuse your code.</p>
<p>The most annoying thing about this all is that magic quotes is actually a very poor solution to the database escaping problem. Firstly, different databases have different escaping rules (I think SQL server requires quotes to be doubled up rather than backslash escaped). Secondly, a far, far more reliable way of safely escaping database variables used be pretty much databases access libraries for loads of other languages is to use something like this:</p>
<p>$query = sql_query(&#8221;select * from table where tag = ? and section = ?&#8221;, $tag, $section);</p>
<p>In magic quotes defence, if the above were used there would always be utterly clueless newbies who still stuck everything together using string concatenation and opened them up to vulnerabilities, but a decent sized warning against this on the manual page for the function would probably be enough to save all but the most hopeless of cases.</p>
<p>This turned in to a bit of a rant, but magic quotes is one of the principle things that turned me away from PHP for large web application development (I use Python now) so it&#8217;s something of a pet peeve!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Manders</title>
		<link>http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/#comment-1924</link>
		<dc:creator>Maarten Manders</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1924</guid>
		<description>&lt;p&gt;Skunk, at http://www.php.net/mysql_real_escape_string#AEN89967 there is an example that does exactly what you suggested. Another (more tedious but faster) way would be formatting any data type manually with sprintf and mysql_real_escape_string.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Skunk, at <a href="http://www.php.net/mysql_real_escape_string#AEN89967" rel="nofollow">http://www.php.net/mysql_real_escape_string#AEN89967</a> there is an example that does exactly what you suggested. Another (more tedious but faster) way would be formatting any data type manually with sprintf and mysql_real_escape_string.</p>]]></content:encoded>
	</item>
</channel>
</rss>
