<?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"
	>

<channel>
	<title>arkinEx Codex</title>
	<atom:link href="http://www.arkinex.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arkinex.com</link>
	<description>the place where all my code can be viewed</description>
	<pubDate>Tue, 05 Aug 2008 11:13:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Automatically Version your Javascript &#038; Stylesheets</title>
		<link>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/</link>
		<comments>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:34:06 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Guides]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[rewrite]]></category>

		<category><![CDATA[stylesheet]]></category>

		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=36</guid>
		<description><![CDATA[Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files.
As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a few [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Automatically+Version+your+Javascript+%26%23038%3B+Stylesheets&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fguides%2F36%2Fauto-version-javascript-stylesheets%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files.</p>
<p>As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a few things needed to make it perfect.<br />
<span id="more-36"></span><br />
First of all, I couldn&#8217;t get the cache code which goes in .htaccess to work, after closer inspection you must make sure mod_expires is enabled on your server (if you run your own), otherwise you will see a 500 error.</p>
<p>Secondly, the autoVer ended up breaking my javascript and stylesheet files as I name them with multiple periods and it was subsequently replacing them all with numbers so i ended up with filenames like <em>framework.1230203232.version.21302302.two.js</em> which is a bit over the top.</p>
<p>Anyway, this is my revised version, for those of you who haven&#8217;t read <a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Particletree</a>, you don&#8217;t necessarily need to, I will cover all the required parts.</p>
<p>First of all, we modify <em>.htaccess</em> so that it sets an expiry date on all stylesheets, images and javascript files.</p>
<p><em>.htaccess</em></p>
<pre class="Style">&lt;FilesMatch "\.(gif|png|jpg|js|css|swf)$"&gt;
    ExpiresActive On
    ExpiresDefault "access plus 10 years"
&lt;/FilesMatch&gt;
#Rules for the versioned files
RewriteRule ^(scripts|css|images)/(.+)\.([a-zA-Z0-9]+)\.(js|css|jpg|gif|png)$ $1/$2.$4 [L]</pre>
<p>This will make all images, stylesheets, flash and javascript cache for 10 years (reduces load on your server and bandwidth costs) and also adds the <em>RewriteRule</em> which handles the version file pointing to the normal files.</p>
<p>Next, we want to add the function, ideally you want this defined on every page, so stick it somewhere good.</p>
<p><em>the Auto Version function</em></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> autoVer<span style="color: #009900;">&#40;</span><span style="color: #000033;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000033;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000033;">$f</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$f</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #cc66cc;">+1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000033;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$f</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the case that php cannot find the file, it still might exist, so the function just returns the parameters it was given.</p>
<p>Next, we rewrite the <em>HEAD</em> part of your html, this file must be <em>PHP</em> for it to work, and the function must be included (either at the top of the page or within another file).</p>
<p><em>My HEAD area</em></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>arkinEx<span style="color: #339933;">.</span>com <span style="color: #339933;">-</span> Autoversion Your Javascript <span style="color: #339933;">&amp;</span> CSS Stylesheets<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>meta name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;author&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;arkinEx&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=autoVer('/resources/stylesheets/design.css')?&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=autoVer('/resources/javascript/mootools-core.js')?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=autoVer('/resources/javascript/mootools-more.js')?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=autoVer('/resources/javascript/mootools-pastejax.js')?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Which, then, will produce a nice output something like this:<br />
&lt;pre lang=&#8221;html&#8221;&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/resources/stylesheets/design.aHegDd.css&#8221; /&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/resources/javascript/mootools-core.a45S.js&#8221;&gt;&lt;/script&gt;</p>
<p>You get the idea, so try it out, let me know how you found it.</p>
<p>The Original Article: &#8220;<a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Automatically Version Your CSS and Javascript Files</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Benchmark your PHP code</title>
		<link>http://www.arkinex.com/php/34/benchmark-your-php-code/</link>
		<comments>http://www.arkinex.com/php/34/benchmark-your-php-code/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 11:51:44 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[benchmark]]></category>

		<category><![CDATA[guide]]></category>

		<category><![CDATA[resource]]></category>

		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=34</guid>
		<description><![CDATA[As a developer I often question myself when I have many occurrences of a function that could be replaced by something else. There are often many ways of achieving the same thing and only opinion standing in the way of a decision.
To solve this problem, I often benchmark certain peices of code multiple times to [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Benchmark+your+PHP+code&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fphp%2F34%2Fbenchmark-your-php-code%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>As a developer I often question myself when I have many occurrences of a function that could be replaced by something else. There are often many ways of achieving the same thing and only opinion standing in the way of a decision.</p>
<p>To solve this problem, I often benchmark certain peices of code multiple times to see which comes out the fastest. In this guide/tutorial I will teach you how to benchmark your own code.</p>
<p><span id="more-34"></span><br />
The first step is to decide what you want to benchmark, I had trouble in figuring out what to test in this benchmark so in this example I am going to do a simple comparison of using <a href="http://php.net/sizeof">sizeOf</a> inside a for loop and outside a for loop.</p>
<p>The second step is to decide how many times you want to repeat a block of code, if its a larger and more intense block I sugget fewer times, for a shorter block, i recommend more times. In this example I have done 100 times to produce a noticably different output time.</p>
<p>The first part of the code which uses sizeOf inside the for loop:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000033;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000033;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000033;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* PUT THE CODE TO BENCHMARK BELOW */</span>
&nbsp;
	<span style="color: #000033;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$a</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000033;">$a</span><span style="color: #339933;">&lt;</span>sizeOf<span style="color: #009900;">&#40;</span><span style="color: #000033;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000033;">$a</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* END OF BENCHMARK CODE */</span>
<span style="color: #009900;">&#125;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$start</span><span style="color: #339933;">,</span><span style="color: #000033;">$i</span><span style="color: #339933;">,</span><span style="color: #000033;">$x</span><span style="color: #339933;">,</span><span style="color: #000033;">$a</span><span style="color: #339933;">,</span><span style="color: #000033;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%01.2fms'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000033;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice, it is important to unset the variables that were set during the test to make it fair.</p>
<p>The second test will be with the <a href="http://php.net/sizeof">sizeOf</a> element outside of the <a href="http://php.net/for">for loop</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000033;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000033;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000033;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* PUT THE CODE TO BENCHMARK BELOW */</span>
&nbsp;
	<span style="color: #000033;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$a</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000033;">$a</span><span style="color: #339933;">&lt;</span><span style="color: #000033;">$s</span><span style="color: #339933;">;</span><span style="color: #000033;">$a</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* END OF BENCHMARK CODE */</span>
<span style="color: #009900;">&#125;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$start</span><span style="color: #339933;">,</span><span style="color: #000033;">$i</span><span style="color: #339933;">,</span><span style="color: #000033;">$x</span><span style="color: #339933;">,</span><span style="color: #000033;">$a</span><span style="color: #339933;">,</span><span style="color: #000033;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%01.2fms'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000033;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also, notice, the only thing that changed here was the addition of <em>$s = sizeOf($x);</em> and the changed variable in the <a href="http://php.net/for">for loop</a>.</p>
<p>The ouput of this test was quite significant:</p>

<div class="wp_syntax"><div class="code"><pre>2.06ms
0.96ms</pre></div></div>

<p>As you can see from the results, the sizeOf is best kept outside of the for loop (cached in a variable), so it is not repeated each time.</p>
<p>I hope this guide has helped, I will post the file online later for download and will be doing a more advanced guide on benchmarking in the next few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/34/benchmark-your-php-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Managing Apache2 on Debian Etch</title>
		<link>http://www.arkinex.com/guides/33/managing-apache2-on-debian-etch/</link>
		<comments>http://www.arkinex.com/guides/33/managing-apache2-on-debian-etch/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 15:32:21 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Guides]]></category>

		<category><![CDATA[apache2]]></category>

		<category><![CDATA[debian]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=33</guid>
		<description><![CDATA[Thought i&#8217;d write a quick guide on managing apache2 once installed and running under debian.
Covers log file management, adding virtual hosts (with subdomains) and basic security.

During this tutorial, it is important that you have root SSH access to your server.
Although this guide is written for Debian, it can be used across many Linux distributions, you [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Managing+Apache2+on+Debian+Etch&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fguides%2F33%2Fmanaging-apache2-on-debian-etch%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Thought i&#8217;d write a quick guide on managing apache2 once installed and running under debian.</p>
<p>Covers log file management, adding virtual hosts (with subdomains) and basic security.<br />
<span id="more-33"></span><br />
During this tutorial, it is important that you have root SSH access to your server.</p>
<p>Although this guide is written for Debian, it can be used across many Linux distributions, you will just need to find the locations of the files mentioned and may need to create some additional files.</p>
<p><strong>Part 1 - Log File Management</strong></p>
<p>First of all, we will navigate to our log file directory. Log files in debian are normally kept in <em>/var/log</em> and apache log files have their own directory, so <em>/var/log/apache2</em>.</p>

<div class="wp_syntax"><div class="code"><pre>mars:~# cd /var/log/apache2
mars:/var/log/apache2# ls
access.log  access.log.1  error.log  error.log.1</pre></div></div>

<p>You may also have seperate log files for specific sites on your server.</p>
<p>Error log is normally the most useful and contains all the errors caught by Apache.<br />
It helps us determine hackers and exploiters and general errors from within our site.</p>
<p>We will use the <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?cat">cat</a> and <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?more">more</a> commands to view &amp; limit the output of the log.</p>

<div class="wp_syntax"><div class="code"><pre>mars:/var/log/apache2# cat error.log <PIPE> more
[Sun Aug 03 14:39:11 2008] [error] [client 125.65.112.135] File does not exist: /var/www/site/cms/favicon.ico
[Sun Aug 03 14:39:14 2008] [error] [client 125.65.112.135] File does not exist: /var/www/site/cms/favicon.ico
[Sun Aug 03 14:44:11 2008] [error] [client 125.65.112.135] File does not exist: /var/www/site/robots.txt, referer: http://your.site.com/
[Sun Aug 03 14:49:11 2008] [error] [client 125.65.112.135] File does not exist: /var/www/site/robots.txt, referer: http://your.site.com/
--More--</pre></div></div>

<p>and/or</p>

<div class="wp_syntax"><div class="code"><pre>mars:/var/log/apache2# cat access.log <PIPE> grep 404 <PIPE> more
mars:/var/log/apache2# cat access.log <PIPE> grep 404
129.241.50.34 - - [01/Aug/2008:20:11:51 +0100] &quot;GET /support.html HTTP/1.1&quot; 404 359 &quot;-&quot; &quot;boitho.com-dc/0.86 ( http://www.boitho.com/dcbot.html )&quot;
82.36.220.196 - - [01/Aug/2008:20:29:03 +0100] &quot;GET /favicon.ico HTTP/1.1&quot; 404 358 &quot;-&quot; &quot;Mozilla/5.0 (Windows<SEMI> U<SEMI> Windows NT 5.1<SEMI> en-US<SEMI> rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1&quot;
82.36.220.196 - - [01/Aug/2008:20:29:06 +0100] &quot;GET /favicon.ico HTTP/1.1&quot; 404 358 &quot;-&quot; &quot;Mozilla/5.0 (Windows<SEMI> U<SEMI> Windows NT 5.1<SEMI> en-US<SEMI> rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1&quot;
--More--</pre></div></div>

<p>This shows us that robots.txt is missing and being requests (by <a href="http://www.robotstxt.org">search engines</a>) and your favicon.ico is also not present (used for bookmark icons &amp; webpage icon in firefox).</p>
<p>If you want to continue through the error log press your space bar, if you want to cancel and do something else, press control+c.</p>
<p>Now we will investigate the above IP address using <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?cat">cat</a>, <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?grep">grep</a> and <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?more">more</a> to pull specific entires from the file and limit them (incase theres alot).</p>

<div class="wp_syntax"><div class="code"><pre>mars:/var/log/apache2# cat access.log <PIPE> grep 125.65.112.135 <PIPE> more
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=FF6E471372BF51AF4E81E79401BB2C0AFB6111933982 HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=E8DA0FF096B5A4DF4E81E794005023B09FEDA25BA2F8 HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=12FC7BCD3E2683FB4E81E79601BB61BEC3540BEC7B0D HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=AC0D7A2AC9C426304E81E797005052BD8A83720EF4F0 HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
&nbsp;
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=ED17C0488BDCD4C34E81E7990050BFA51AADCB0A9512 HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
125.65.112.135 - - [02/Aug/2008:07:21:27 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=B58AD75AA8EF6EDA4E81E79A01BB2B30977E22A9B821 HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;
125.65.112.135 - - [02/Aug/2008:07:21:30 +0100] &quot;GET http://www.wantsfly.com/prx1.php?hash=FF9A1DBB63B403CE4E81E79801BBEF64B8651E15FF6B HTTP/1.0&quot; 404 356 &quot;-&quot; &quot;Mozilla/4.0 (compatible<SEMI> MSIE 6.0<SEMI> Windows NT 5.0)&quot;</pre></div></div>

<p>So now we can see, this user has been naughty trying to referal spam us using a website that doesn&#8217;t exist on our server. This is quite common, and the suspected user is obviously forging his user agent (as internet explorer).</p>
<p>If there is one particular IP address or Browser you want to &#8220;count&#8221; you can use the word count <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?wc">wc</a> command.</p>
<p>For this example, I am going to count all pageviews from the IP range 127.0.0&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre>mars:/var/log/apache2# cat access.log <PIPE> grep 127.0.0 <PIPE> wc -l
78</pre></div></div>

<p>This shows that 127.0.0.* has accessed 78 files on our server in the log period. The ip address could be replaced with MSIE to count Internet Explorer accesses or Firefox etc.</p>
<p>If you require more examples or additional information, please leave questions in the comments section.</p>
<p><strong>Part 2 - Adding Apache Virtual Hosts</strong></p>
<p>So, if you are dealing with a default apache2 setup (like I am), your virtual hosts can be found in <em>/etc/apache2/sites-enabled/</em> directory and all these files are loaded as apache reloads. <strong>If you do not have this directory</strong>, add the entries to the end of your main Apache configuration file, and make sure <em>NameVirtualHost *</em> is above them all.</p>
<p>I try and create my virtual hosts in numeric sequence order.</p>

<div class="wp_syntax"><div class="code"><pre>mars:/etc/apache2/sites-enabled# ls
000-default</pre></div></div>

<p>So were gonna create <em><strong>001</strong>-example</em> for example.com. I add all my domains in <em>/var/www</em> and give them all a single letter prefix also, so <em>/var/www/e/example</em> for our example site.</p>

<div class="wp_syntax"><div class="code"><pre>mars:/etc/apache2/sites-enabled# mkdir -p /var/www/e/example
mars:/etc/apache2/sites-enabled# nano 001-example</pre></div></div>

<p>This creates a new file using nano. You can then start adding the configuration.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;VirtualHost *%gt<SEMI>
        ServerAdmin webmaster@localhost
        ServerName www.example.com
        ServerAlias example.com example.net  www.example.net
        DocumentRoot /var/www/e/example
&nbsp;
#        ErrorLog /var/log/apache2/error.log
&nbsp;
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
#        LogLevel warn
&nbsp;
#        CustomLog /var/log/apache2/access.log combined
#        ServerSignature On
&lt;/VirtualHost&gt;</pre></div></div>

<p>This adds <em>www.example.com</em> as the main domain, and also adds <em>example.com example.net www.example.net</em> as addon domains. You could also add <em>*.example.com</em> under ServerAlias to pick up <em>anything.example.com</em>.</p>
<p>If you are getting permission errors, dont forget to <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?chown">chown</a> and <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?chmod">chmod</a> your <em>/var/www/e/example</em> directory to the right user with the right permssions.</p>
<p>You will also need to reload apache2 for the changes to take effect.</p>

<div class="wp_syntax"><div class="code"><pre>mars:/etc/apache2/sites-enabled# /etc/init.d/apache2 restart
Forcing reload of web server (apache2)... waiting .
mars:/etc/apache2/sites-enabled#</pre></div></div>

<p><strong>Part 3 - Basic Security</strong></p>
<p>In the last part of this guide we will review basic security, the following lines can be added in the <VirtualHost> configuration, in the main configuration file, or even in a .htaccess in the desired directory.</p>
<p>How to block all users except 1 IP address:</p>

<div class="wp_syntax"><div class="code"><pre># If the REMOTE_ADDR (Ip address) isn't 127.0.0.1.
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
# On any page (.*), F=Forbidden, L=Last Rule.
RewriteRule .* - [F,L]</pre></div></div>

<p>How to block users to the downloads directory who didn&#8217;t come from your site.</p>

<div class="wp_syntax"><div class="code"><pre># If the user didn't come from www.mydomain.com or sub.mydomain.com
RewriteRule %{HTTP_REFERER} !^www.mydomain.com [NC,OR]
RewriteRule %{HTTP_REFERER} !^sub.mydomain.com [NC]
# And they are trying to access anything under the downloads/ folder.
# Then redirect them to http://www.mydomain.com/invalid-referer.html
RewriteRule downloads/(.*) /invalid-referer.html [R=302,L]</pre></div></div>

<p>I hope you enjoyed reading this guide, please leave comments if you need help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/33/managing-apache2-on-debian-etch/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Swear Words Text File Resource</title>
		<link>http://www.arkinex.com/blog/32/swear-words-text-file-dl/</link>
		<comments>http://www.arkinex.com/blog/32/swear-words-text-file-dl/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 22:16:20 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<category><![CDATA[filter]]></category>

		<category><![CDATA[swearwords]]></category>

		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=32</guid>
		<description><![CDATA[When browsing the internet today I found it impossible to find a neat list of swear words in a basic text file. Upon discovering their was none available I decided to create my own for my users and upcoming projects.
Here is a list of swearwords I put together on July 14th 2008, it contains a [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Swear+Words+Text+File+Resource&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fblog%2F32%2Fswear-words-text-file-dl%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>When browsing the internet today I found it impossible to find a neat list of swear words in a basic text file. Upon discovering their was none available I decided to create my own for my users and upcoming projects.<span id="more-32"></span></p>
<p>Here is a list of swearwords I put together on <em>July 14th 2008</em>, it contains a total of <strong>175 words</strong> that may be deemed offensive and possibly racist.</p>
<ul>
<li><a href="http://www.arkinex.com/resources/swearwords/swearwords.txt">swearwords.txt</a> (1.51Kb)</li>
</ul>
<p>I will try keep the list updated based on your suggestions, comments and any words that i personally come across.</p>
<p>You may find this bad word file useful when working with my <a href="http://www.arkinex.com/php/tutorials/simple-swear-filter-tutorial/" target="_blank">Simple Swear filter tutorial</a>, which teaches you how to filter swear words from content on your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/blog/32/swear-words-text-file-dl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Function: str_remove()</title>
		<link>http://www.arkinex.com/php/functions/31/php-function-str_remove/</link>
		<comments>http://www.arkinex.com/php/functions/31/php-function-str_remove/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 16:28:33 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/blog/31/php-function-str_remove/</guid>
		<description><![CDATA[Thought it&#8217;d be useful and make more sense to make a str_remove() function because there isn&#8217;t one.


function str_remove&#40;$word, $str&#41; &#123;
return str_replace&#40;$word, '', $str&#41;;
&#125;

<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=PHP+Function%3A+str_remove%28%29&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fphp%2Ffunctions%2F31%2Fphp-function-str_remove%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Thought it&#8217;d be useful and make more sense to make a str_remove() function because there isn&#8217;t one.</p>
<p><span id="more-31"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> str_remove<span style="color: #009900;">&#40;</span><span style="color: #000033;">$word</span><span style="color: #339933;">,</span> <span style="color: #000033;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$word</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000033;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/functions/31/php-function-str_remove/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating a .tar.gz Backup on Linux</title>
		<link>http://www.arkinex.com/guides/30/creating-a-targz-backup-on-linux/</link>
		<comments>http://www.arkinex.com/guides/30/creating-a-targz-backup-on-linux/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 17:47:34 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Guides]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/guides/30/creating-a-targz-backup-on-linux/</guid>
		<description><![CDATA[Very useful commmand to make a .tar.gz compressed backup of important directories.

tar stands for tape archive which can be used to turn many files and directories into a single file, great for backup and storage.
The syntax:

tar [-options] /directory/of/new/file.tar /files/to/backup/*

So, in this example, we want to backup /var/www to /var/backup.tar.gz (.gz are further compressed).
We would use [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Creating+a+.tar.gz+Backup+on+Linux&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fguides%2F30%2Fcreating-a-targz-backup-on-linux%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Very useful commmand to make a .tar.gz compressed backup of important directories.</p>
<p><span id="more-30"></span></p>
<p><strong>tar</strong> stands for <em>tape archive</em> which can be used to turn many files and directories into a single file, great for backup and storage.</p>
<p>The syntax:</p>
<pre>
tar [-options] /directory/of/new/file.tar /files/to/backup/*
</pre>
<p>So, in this example, we want to backup <em>/var/www</em> to <em>/var/backup.tar.gz</em> (.gz are further compressed).</p>
<p>We would use this command:</p>
<pre>
tar -pczf /var/backup.tar.gz /var/www/*
</pre>
<p>What the options mean:</p>
<pre>
-f = read to/from the named file (instead of the device /tape)
-t = list contents of .tar file
-p = maintain permissions (users/groups)
-r = append to a .tar file
-v = verbose (tells you everything its doing)
-x = extract contents of .tar file
-z = compress files (not so useful for minc files)
</pre>
<p>Then, if we wanted to extract the backup.</p>
<pre>
tar -zxvf backup.tar.gz
</pre>
<p>Hope this helps, very useful command.<br />
Especially if you can run it on a cronjob.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/30/creating-a-targz-backup-on-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Upgrade PHP5 &#038; MySQL 5 to latest on Debian</title>
		<link>http://www.arkinex.com/guides/29/upgrade-php5-mysql-5-to-latest-on-debian/</link>
		<comments>http://www.arkinex.com/guides/29/upgrade-php5-mysql-5-to-latest-on-debian/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 14:32:27 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Guides]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/guides/29/upgrade-php5-mysql-5-to-latest-on-debian/</guid>
		<description><![CDATA[Sometimes the packages on your desired apt-get mirror aren&#8217;t kept up to date.
A friend recently showed me how to upgrade to the latest and securist version using a special apt-get mirror service that specializes in LAMP installations.
 We will be using a service called dotdeb to update PHP5 and MySQL5. It is an unoffical Debian [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Upgrade+PHP5+%26%23038%3B+MySQL+5+to+latest+on+Debian&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fguides%2F29%2Fupgrade-php5-mysql-5-to-latest-on-debian%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Sometimes the packages on your desired apt-get mirror aren&#8217;t kept up to date.<br />
A friend recently showed me how to upgrade to the latest and securist version using a special apt-get mirror service that specializes in LAMP installations.</p>
<p><span id="more-29"></span> We will be using a service called <a href="http://www.dotdeb.org/" target="_blank">dotdeb</a> to update PHP5 and MySQL5. It is an unoffical Debian respository containing many packages for the Debian (Sarge) stable release but specifically packages &#8220;to turn your <a href="http://www.debian.org/" class="urlextern" title="http://www.debian.org/" rel="nofollow">Debian GNU/Linux</a> boxes into powerful, stable and up-to-date LAMP servers.&#8221;</p>
<p>Its really simple to use and active.</p>
<p>First:</p>
<pre>nano /etc/apt/sources.list</pre>
<p>Then, scroll to the bottom of the file and add:</p>
<pre>deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all</pre>
<p>Then, save and exit the file and run:</p>
<pre>apt-get update &amp;&amp; apt-get upgrade</pre>
<p>This should upgrade your MySQL 4.1 or 5 installation and upgrade and harden your PHP 4 or 5 installation. You can also <a href="http://packages.dotdeb.org/" target="_blank">browse the repository</a> and <a href="http://www.dotdeb.org/mirrors" title="Dotdeb Mirror Locations" target="_blank">find a closer mirror</a>  at Dotdeb if you wish to do so.</p>
<p>Hope this helps keep your LAMP installation up to date, it worked for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/29/upgrade-php5-mysql-5-to-latest-on-debian/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing and Configuring Samba on Debian 4</title>
		<link>http://www.arkinex.com/guides/28/installing-and-configuring-samba-on-debian-4-etch/</link>
		<comments>http://www.arkinex.com/guides/28/installing-and-configuring-samba-on-debian-4-etch/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 12:18:34 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Guides]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/guides/28/installing-and-configuring-samba-on-debian-4-etch/</guid>
		<description><![CDATA[In this guide you will learn how to install Samba on Linux (Debian 4 / etch).
Installing Samba allows you to share files over the network for Mac, Windows and other Linux computers.

As always, first of all lets update the Aptitude source list so we get the latest version.
apt-get update
Next, lets install Samba and the client [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Installing+and+Configuring+Samba+on+Debian+4&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fguides%2F28%2Finstalling-and-configuring-samba-on-debian-4-etch%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>In this guide you will learn how to install Samba on Linux (Debian 4 / etch).<br />
Installing Samba allows you to share files over the network for Mac, Windows and other Linux computers.</p>
<p><span id="more-28"></span></p>
<p>As always, first of all lets update the Aptitude source list so we get the latest version.</p>
<pre>apt-get update</pre>
<p>Next, lets install Samba and the client for Samba (to connect).</p>
<pre>apt-get install samba smbclient</pre>
<p>The configuration file can be found at <em>/etc/samba/smb.conf</em>.</p>
<p>We don&#8217;t want to use the generated file, as it&#8217;s bloated.<br />
Its a good reference for additional parameters, but for these guide we&#8217;ll make our own.</p>
<pre>cd /etc/samba
mv smb.conf smb.conf.old</pre>
<p>Now lets create our own:</p>
<pre>nano smb.conf</pre>
<p>And in this file, put the following:</p>
<pre>[global]

workgroup = debian
netbios name = debian server
server string = %h server (Samba %v)
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

[WEB]

path=/var/www
browseable=yes
writeable=yes
admin users = arkinEx</pre>
<p>Then press <em>Ctrl+X</em> to exit, <em>Y</em> to Save changes and then <em>Enter</em> to confirm filename.<br />
If the file does not save, you are probably not logged in as root, so <em>su root</em> and try again.</p>
<p>As you can see, i set up Samba for my Apache/Web directory.<br />
The [WEB] is a configuration option for a shared directory, you can change this as you need.<br />
The admin users is the list of users whom can read &amp; write the directory, I&#8217;ve added myself.</p>
<p>Once you&#8217;ve added your user to Samba and created your shared directory you will need to add a user to Samba and give it a password. No users on the machine will have access to Samba until you do this. This can be done using the <em>smbpasswd</em> utility:</p>
<pre>smbpasswd -a arkinEx</pre>
<p>Replacing arkinEx with your username, this will add the user to Samba and allow you to provide a password for them.</p>
<pre>smbpasswd -h</pre>
<p>For more information on this command. Alternitavely, check the <a href="http://us1.samba.org/samba/docs/man/manpages-3/smbpasswd.5.html">smbpasswd man page</a>.</p>
<p>Next, lets reload Samba:</p>
<pre>/etc/init.d/samba restart</pre>
<p>Now thats complete, you should be able to find your Debian server on your Mac or Windows network by entering the IP or Hostname of it.</p>
<p>For example, connecting to samba from Mac, on my Macintosh:</p>
<pre>Load Finder
Go -&gt; Connect to Server
smb://mars/WEB</pre>
<p>And then i enter my credentials and wallah, its connected!<br />
Don&#8217;t forget to change <em>mars</em> and <em>WEB</em> to match your Samba setup.</p>
<p>Hope this guide helped, don&#8217;t hesitate to post questions as comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/28/installing-and-configuring-samba-on-debian-4-etch/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Javascript Function: strip_tags()</title>
		<link>http://www.arkinex.com/javascript/js-functions/27/javascript-function-strip_tags/</link>
		<comments>http://www.arkinex.com/javascript/js-functions/27/javascript-function-strip_tags/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 01:19:52 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/blog/27/javascript-function-strip_tags/</guid>
		<description><![CDATA[A useful function to mimic to PHP function strip_tags() to strip all HTML tags and markup from a string.
Useful when parsing client input on the fly. Extra checks should be added though.

The code:

function strip_tags&#40;str&#41; &#123;
   return str.replace&#40;/&#60;\/?[^&#62;]+&#62;/gi, &#34;&#34;&#41;;
&#125;

An example:

alert&#40;strip_tags&#40;'&#60;strong&#62;&#60;em&#62;See the HTML around this message?&#60;/em&#62;&#60;/strong&#62;'&#41;&#41;;
// The html tags won't show in this message.

Hope you [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Javascript+Function%3A+strip_tags%28%29&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fjavascript%2Fjs-functions%2F27%2Fjavascript-function-strip_tags%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>A useful function to mimic to PHP function strip_tags() to strip all HTML tags and markup from a string.</p>
<p>Useful when parsing client input on the fly. Extra checks should be added though.</p>
<p><span id="more-27"></span><br />
The code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> strip_tags<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">return</span> str.<span style="color: #006600;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;\/?[^&gt;]+&gt;/gi</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>An example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>strip_tags<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;strong&gt;&lt;em&gt;See the HTML around this message?&lt;/em&gt;&lt;/strong&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// The html tags won't show in this message.</span></pre></div></div>

<p>Hope you find this useful in your projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/javascript/js-functions/27/javascript-function-strip_tags/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Javascript Function: htmlentities()</title>
		<link>http://www.arkinex.com/javascript/js-functions/26/javascript-function-htmlentities/</link>
		<comments>http://www.arkinex.com/javascript/js-functions/26/javascript-function-htmlentities/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 01:16:14 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/javascript/js-functions/26/javascript-function-htmlentities/</guid>
		<description><![CDATA[Convert html tags and code to readable HTML entities. Mimics the PHP functions htmlspecialchars() and htmlentities().
Prevents from HTML script injection.

The code (Updated July 14th):

function html_entity_decode&#40;s&#41; &#123;
var t=document.createElement&#40;’textarea’&#41;;
t.innerHTML = s;
var v = t.value;
t.parentNode.removeChild&#40;t&#41;;
return v;
&#125;

The old code, which still works:

function htmlentities&#40;str&#41; &#123;
    var i,output='',len,char='';
    len = str.length;
    for&#40;i=0;i47 [...]<p><a href="http://sharethis.com/item?&#038;wp=2.6&#38;publisher=a0f6e893-0b93-4bfe-9773-262bca38f641&#38;title=Javascript+Function%3A+htmlentities%28%29&#38;url=http%3A%2F%2Fwww.arkinex.com%2Fjavascript%2Fjs-functions%2F26%2Fjavascript-function-htmlentities%2F">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p>Convert html tags and code to readable HTML entities. Mimics the PHP functions htmlspecialchars() and htmlentities().<br />
Prevents from HTML script injection.</p>
<p><span id="more-26"></span><br />
The code (<em>Updated July 14th</em>):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> html_entity_decode<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> t<span style="color: #339933;">=</span>document.<span style="color: #006600;">createElement</span><span style="color: #009900;">&#40;</span>’textarea’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
t.<span style="color: #006600;">innerHTML</span> <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> t.<span style="color: #006600;">value</span><span style="color: #339933;">;</span>
t.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> v<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The old code, which still works:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> htmlentities<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">,</span>output<span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>len<span style="color: #339933;">,</span>char<span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
    len <span style="color: #339933;">=</span> str.<span style="color: #006600;">length</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i47 <span style="color: #339933;">&amp;&amp;</span> char<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">58</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>char<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">62</span> <span style="color: #339933;">&amp;&amp;</span> char<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">127</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            output <span style="color: #339933;">+=</span> str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
            output <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&amp;#&quot;</span> <span style="color: #339933;">+</span> str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006600;">charCodeAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> output<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>May also be good for encrypting email address&#8217;s. Will need slight modification.<br />
Hope this function became as handy as it did for me.</p>
<p>Anyone need htmlunentities() or html_decode_entities(), hehe?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/javascript/js-functions/26/javascript-function-htmlentities/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.795 seconds -->
