<?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" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" > <channel><title>Comments on: Prevent code injection in PHP</title> <atom:link href="http://neo22s.com/prevent-code-injection-in-php/feed/" rel="self" type="application/rss+xml" /><link>http://neo22s.com/prevent-code-injection-in-php/</link> <description>Web development, scripts, source code and IT stuff</description> <lastBuildDate>Tue, 02 Mar 2010 14:24:03 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>By: Chema</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-533</link> <dc:creator>Chema</dc:creator> <pubDate>Wed, 04 Nov 2009 21:00:41 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-533</guid> <description>Rally useful Steve! I just bookmark it! nice ;)</description> <content:encoded><![CDATA[<p>Rally useful Steve! I just bookmark it! nice ;)</p> ]]></content:encoded> </item> <item><title>By: Steve</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-531</link> <dc:creator>Steve</dc:creator> <pubDate>Wed, 04 Nov 2009 19:44:55 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-531</guid> <description>Here&#039;s a tutorial I wrote about creating a BBCode parser function: http://www.ultramegatech.com/blog/2009/04/creating-a-bbcode-parser/You also might be interested in this PECL extension, which seems to allow more advanced parsing: http://www.php.net/manual/book.bbcode.php</description> <content:encoded><![CDATA[<p>Here&#8217;s a tutorial I wrote about creating a BBCode parser function:<br /> <a href="http://www.ultramegatech.com/blog/2009/04/creating-a-bbcode-parser/" rel="nofollow">http://www.ultramegatech.com/blog/2009/04/creating-a-bbcode-parser/</a></p><p>You also might be interested in this PECL extension, which seems to allow more advanced parsing:<br /> <a href="http://www.php.net/manual/book.bbcode.php" rel="nofollow">http://www.php.net/manual/book.bbcode.php</a></p> ]]></content:encoded> </item> <item><title>By: Chema</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-522</link> <dc:creator>Chema</dc:creator> <pubDate>Wed, 04 Nov 2009 08:18:07 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-522</guid> <description>yes I think you are right and bbcode is better .Thanks for your sharing and if you have any example off bbcode is welcome.</description> <content:encoded><![CDATA[<p>yes I think you are right and bbcode is better .</p><p>Thanks for your sharing and if you have any example off bbcode is welcome.</p> ]]></content:encoded> </item> <item><title>By: Steve</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-514</link> <dc:creator>Steve</dc:creator> <pubDate>Tue, 03 Nov 2009 21:56:15 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-514</guid> <description>Sorry, the code above got messed up. Here it is again:&lt;pre&gt;$clean = array_map(&#039;clean_input&#039;, $_POST); function clean_input($value) { return strip_tags($value, &#039;&lt;em&gt;&lt;strong&gt;&#039;); }&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>Sorry, the code above got messed up. Here it is again:</p><pre>$clean = array_map('clean_input', $_POST);
function clean_input($value)
{
   return strip_tags($value, '<em><strong>');
}</strong></em></pre>]]></content:encoded> </item> <item><title>By: Steve</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-513</link> <dc:creator>Steve</dc:creator> <pubDate>Tue, 03 Nov 2009 21:52:49 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-513</guid> <description>You can also do something like this to provide a white list of allowed tags. In this example, it allows p, em, and strong tags. Any CSS can be applied to these tags as well.$clean = array_map(&#039;clean_input&#039;, $_POST); function clean_input($value) { return strip_tags($value, &#039;&lt;em&gt;&lt;strong&gt;&#039;); }Keep in mind that allowing some tags will also allow JavaScript injection, so it might be best to use BBCode type tags instead of allowing any HTML.</description> <content:encoded><![CDATA[<p>You can also do something like this to provide a white list of allowed tags. In this example, it allows p, em, and strong tags. Any CSS can be applied to these tags as well.</p><p>$clean = array_map(&#8216;clean_input&#8217;, $_POST);<br /> function clean_input($value)<br /> {<br /> return strip_tags($value, &#8216;<em><strong>&#8216;);<br /> }</p><p>Keep in mind that allowing some tags will also allow JavaScript injection, so it might be best to use BBCode type tags instead of allowing any HTML.</strong></em></p> ]]></content:encoded> </item> <item><title>By: Chema</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-512</link> <dc:creator>Chema</dc:creator> <pubDate>Tue, 03 Nov 2009 20:59:39 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-512</guid> <description>Hi Steve,Thanks for the info it is really usefull, your proposal is really good, but for example in my case I want it to allow css style. With the code that I propose it is possible since you can just comment the line and then it would be allowed.Another time thanks for the info ;)</description> <content:encoded><![CDATA[<p>Hi Steve,</p><p>Thanks for the info it is really usefull, your proposal is really good, but for example in my case I want it to allow css style. With the code that I propose it is possible since you can just comment the line and then it would be allowed.</p><p>Another time thanks for the info ;)</p> ]]></content:encoded> </item> <item><title>By: Steve</title><link>http://neo22s.com/prevent-code-injection-in-php/comment-page-1/#comment-511</link> <dc:creator>Steve</dc:creator> <pubDate>Tue, 03 Nov 2009 17:48:26 +0000</pubDate> <guid isPermaLink="false">http://neo22s.com/?p=601#comment-511</guid> <description>You&#039;ll probably be better off using the strip_tags function to remove any HTML tags. There&#039;s also htmlspecialchars and htmlentities to convert special characters to entities. Something like the below code will remove tags from input: $_POST = array_map(&#039;strip_tags&#039;, $_POST); $_GET = array_map(&#039;strip_tags&#039;, $_GET);Note that strip_tags also accepts a white list of allowed tags. Alternatively, the below will cause special characters to be displayed as text and not rendered by the browser: $_POST = array_map(&#039;htmlentities&#039;, $_POST); $_GET = array_map(&#039;htmlentities&#039;, $_GET);Also, the ereg* functions have been deprecated in favor of preg* functions for regular expressions.http://www.php.net/manual/function.strip-tags.php http://www.php.net/manual/function.htmlspecialchars.php http://www.php.net/manual/function.htmlentities.php http://www.php.net/manual/function.array-map.phpI hope you find this useful. :)</description> <content:encoded><![CDATA[<p>You&#8217;ll probably be better off using the strip_tags function to remove any HTML tags. There&#8217;s also htmlspecialchars and htmlentities to convert special characters to entities. Something like the below code will remove tags from input:<br /> $_POST = array_map(&#8217;strip_tags&#8217;, $_POST);<br /> $_GET = array_map(&#8217;strip_tags&#8217;, $_GET);</p><p>Note that strip_tags also accepts a white list of allowed tags. Alternatively, the below will cause special characters to be displayed as text and not rendered by the browser:<br /> $_POST = array_map(&#8216;htmlentities&#8217;, $_POST);<br /> $_GET = array_map(&#8216;htmlentities&#8217;, $_GET);</p><p>Also, the ereg* functions have been deprecated in favor of preg* functions for regular expressions.</p><p><a href="http://www.php.net/manual/function.strip-tags.php" rel="nofollow">http://www.php.net/manual/function.strip-tags.php</a><br /> <a href="http://www.php.net/manual/function.htmlspecialchars.php" rel="nofollow">http://www.php.net/manual/function.htmlspecialchars.php</a><br /> <a href="http://www.php.net/manual/function.htmlentities.php" rel="nofollow">http://www.php.net/manual/function.htmlentities.php</a><br /> <a href="http://www.php.net/manual/function.array-map.php" rel="nofollow">http://www.php.net/manual/function.array-map.php</a></p><p>I hope you find this useful. :)</p> ]]></content:encoded> </item> </channel> </rss>
<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk
Database Caching 4/16 queries in 0.232 seconds using disk
Content Delivery Network via Amazon Web Services: S3: neo22s.s3.amazonaws.com

Served from: ps20232.dreamhostps.com @ 2010-03-13 10:56:23 -->