<?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>Juozas devBlog &#187; spam</title>
	<atom:link href="http://dev.juokaz.com/tag/spam/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spam-safe email links</title>
		<link>http://dev.juokaz.com/php/spam-safe-email-links</link>
		<comments>http://dev.juokaz.com/php/spam-safe-email-links#comments</comments>
		<pubDate>Tue, 10 Feb 2009 16:21:13 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[anchor]]></category>
		<category><![CDATA[bin2hex]]></category>
		<category><![CDATA[crypt]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[hiding]]></category>
		<category><![CDATA[image hide]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=76</guid>
		<description><![CDATA[There are thousands of ways to protect your email from being read by a spam bot. Complex ones uses images or Flash to display email as graphics, other uses JavaScript to dynamically create email anchors. I always try to use simple and still powerful methods, which both work as expected and are easy to implement, [...]]]></description>
			<content:encoded><![CDATA[<p>There are thousands of ways to protect your email from being read by a spam bot. Complex ones uses images or Flash to display email as graphics, other uses JavaScript to dynamically create email anchors. I always try to use simple and still powerful methods, which both work as expected and are easy to implement, today I&#8217;m going to show email protection in my way.</p>
<p>For email addresses hiding I use simple <a href="http://www.php.net">PHP</a> function, which takes email address as a string and HEX-encodes it. This function can also create whole anchor tag for you if you specify text for anchor (<em>&lt;a&gt;TEXT&lt;/a&gt;</em>). Code looks like this (main part from <a href="http://www.smarty.net">Smarty</a> plugin &#8220;mailto&#8221;):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getMailToEncoded <span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$address_prepend</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mailto:'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$address_encode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address_prepend</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$address_encode</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">.</span> <span style="color: #990000;">bin2hex</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address_prepend</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</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: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'!\w!'</span><span style="color: #339933;">,</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$address_encode</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'%'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">bin2hex</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$address_encode</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$address</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span>
           <span style="color: #b1b100;">return</span> <span style="color: #000088;">$address_encode</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$text_encode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	   <span style="color: #000088;">$text_encode</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">.</span> <span style="color: #990000;">bin2hex</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$address_encode</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$text_encode</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> getMailToEncoded <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'juozas@juokaz.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'email me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Output will look like this: <a href="mailto:%6a%75%6f%7a%61%73@%6a%75%6f%6b%61%7a.%63%6f%6d">email me</a>, but actual HTML code has been transformed to:</p>
<p>&lt;a href=&#8221;&amp;#x6d;&amp;#x61;&amp;#x69;&amp;#x6c;&amp;#x74;&amp;#x6f;&amp;#x3a;%6a%75%6f%7a%61%73@%6a%75%6f%6b%61%7a.%63%6f%6d&#8221;&gt;&amp;#x65;&amp;#x6d;&amp;#x61;&amp;#x69;&amp;#x6c;&amp;#x20;&amp;#x6d;&amp;#x65;&lt;/a&gt;</p>
<p>Nasty! Bots are getting smarter and smarter, so after a while they will understand this code, but for initial protection this code works well. If you want additional protection, you can easily modify this function to put output in javascript block, where hex-encoded string is outputted by unescape() and then eval() functions. Try it!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/spam-safe-email-links/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
