<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mindloop BVBA &#187; html</title>
	<atom:link href="http://www.mindloop.be/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mindloop.be</link>
	<description>Webdesign and webdevelopment</description>
	<lastBuildDate>Fri, 17 Dec 2010 16:07:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Htmlpurifier and the CodeIgniter framework</title>
		<link>http://www.mindloop.be/htmlpurifier-and-the-codeigniter-framework/</link>
		<comments>http://www.mindloop.be/htmlpurifier-and-the-codeigniter-framework/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 15:45:41 +0000</pubDate>
		<dc:creator>Andy Mathijs</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://mindloop.loc/?p=39</guid>
		<description><![CDATA[Intro HtmlPurifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all (&#8230;)]]></description>
			<content:encoded><![CDATA[<h2>Intro</h2>
<p>HtmlPurifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant.</p>
<p>Although Codeigniter comes with it&#8217;s own XSS filtering method <span class="php-code">$this-&gt;input-&gt;xss_clean()</span> I prefer the use of the HtmlPurifier because of 2 reasons :<br />
1) HTMLpurifier will make sure that user input is converted to 	valid xhtml<br />
2) HTMLpurifier is tested against every element on the notorious 	<a href="http://ha.ckers.org/xss.html">XSS cheat sheet</a></p>
<h2 class="western">Installing htmlPurifier in codeigniter</h2>
<p>Since codeigniter is PHP4 and PHP5 compatible we&#8217;ll start out by downloading the php4 compatible version of htmlPurifier (<a href="http://htmlpurifier.org/download.html">http://htmlpurifier.org/download.html</a>)</p>
<p>Once you&#8217;ve downloaded and extracted the archive you&#8217;ll just have to copy the contents of the /htmlpurifier-2.0.1/library folder into your codeigniter /system/application/libraries folder.</p>
<p>HtmlPurifier comes with an HTMLPurifier.auto.php file that automagically changes your include path to include the neccessary folder. We&#8217;ll delete this file and make one small change to HTMLPurifier.php.</p>
<p>Just add</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>just below the</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></pre></div></div>

<p>line in HTMLPurifier.php and we&#8217;re ready to go.</p>
<h2>Small demo</h2>
<p>Add this testcontroller and check out the results :</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> Test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="">'HTMLPurifier'</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$dirty_html</span> <span style="color: #339933;">=</span> <span style="">'&lt;a href=&quot;javascript:alert(<span style="">\'</span>test<span style="">\'</span>)&quot;&gt;ds&lt;/a&gt;&lt;p&gt;test&lt;br /&gt;&lt;img src=&quot;noalt.jpg&quot;&gt;'</span>;
        <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> HTMLPurifier_Config<span style="color: #339933;">::</span><span style="color: #004000;">createDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$clean_html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">htmlpurifier</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">purify</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$dirty_html</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$config</span> <span style="color: #009900;">&#41;</span>;
        <span style="color: #990000;">echo</span> <span style="color: #000088;">$clean_html</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span class="article_seperator"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mindloop.be/htmlpurifier-and-the-codeigniter-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

