<?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>PHP and Web Development Blog &#187; SEO</title>
	<atom:link href="http://www.ebrueggeman.com/blog/category/seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ebrueggeman.com/blog</link>
	<description>Tips and Tricks for Web Developers</description>
	<lastBuildDate>Tue, 03 Aug 2010 17:21:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hiding Email Addresses and Names from Search Engines in PHP</title>
		<link>http://www.ebrueggeman.com/blog/hiding-email-addresses-and-names-from-search-engines-in-php/</link>
		<comments>http://www.ebrueggeman.com/blog/hiding-email-addresses-and-names-from-search-engines-in-php/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 03:32:28 +0000</pubDate>
		<dc:creator>Elliott Brueggeman</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Search Engines]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[hide email]]></category>
		<category><![CDATA[php image]]></category>
		<category><![CDATA[search engine]]></category>

		<guid isPermaLink="false">http://www.ebrueggeman.com/blog/php/hiding-email-addresses-and-names-from-search-engines-in-php/</guid>
		<description><![CDATA[Background
Displaying your email address on your site as text has always been risky. Why? Long ago, spammers created bots that searched the web for email address (by looking for something in the xxxx@yyyy.com format) and then spammed them to oblivion. As a result, web developers often use little tricks like writing out the @ symbol [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>Displaying your email address on your site as text has always been risky. Why? Long ago, spammers created bots that searched the web for email address (by looking for something in the xxxx@yyyy.com format) and then spammed them to oblivion. As a result, web developers often use little tricks like writing out the @ symbol (xxxx at yyyy.com) or inserting a little image of an @ symbol between the username and the domain to prevent a spambot from reading the address. Another problem arises when a user wants to display their name on a website, but doesn&#8217;t want a search engine to be able to read the name and then associate it with the site in the engine&#8217;s search results. PHP allows a solution for both of these scenarios that is versatile and easy to implement.</p>
<h2>Dynamically Generated Images</h2>
<p>One of the many powers of PHP is its ability to generate images dynamically, meaning on the fly, when a page is requested. PHP uses the GD extension to create gifs, pngs, jpegs, etc and manipulate them with a small set of predefined functions. The idea here is to display a dynamically generated image of your name or email address that is invisible to search engines, because it is an image and not text.</p>
<p>Why not use Photoshop or another similar program to make an image of a name for one time use? Well you could do this, but what about a situation where data is displayed dynamically, like on a blogging site, where new users sign without the intervention of a web developer? You wouldn&#8217;t want to have to manually create an image each time this happened. Dynamically created images in PHP are the solution.</p>
<h2>Inserting Dynamic Images Into Your Site</h2>
<p>PHP scripts that generate images can only generate images. They cannot have html or other PHP elements echo&#8217;d out to the screen. In order to get them to work, you have to isolate the script that generates the image from the script (or page) that displays the image. Let&#8217;s say we want to display our email address on our page home.php, and we have a script that generates the image of our email address in email_address.php. To accomplish this, we would need to have an &lt;img&gt; tag on home.php that pointed to email_address.php. Here is what the tag on home.php could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email_address.php&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></div>

<p>Note that we are substituting our image generating script into the spot where we would normally have the name of an image, but we keep the &#8220;.php&#8221; extension.</p>
<h2>The Script</h2>
<p>To use this script, copy the below code into a file and save it as disguise_text.php and upload it to your server. Then, follow the instructions in the &#8220;Implementing the Script&#8221; section.</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: #666666; font-style: italic;">//get name from passed arg</span>
<span style="color: #000088;">$text</span><span style="color: #339933;">=</span> <span style="color: #990000;">base64_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>text<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//width per char is based on experimentation - yours may be different</span>
<span style="color: #000088;">$width_per_char</span> <span style="color: #339933;">=</span> <span style="color:#800080;">6.25</span>;
<span style="color: #666666; font-style: italic;">//image height and width</span>
<span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width_per_char</span> <span style="color: #339933;">*</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: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span>;
<span style="color: #666666; font-style: italic;">//create image</span>
<span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> imagecreatetruecolor<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//define used colors</span>
<span style="color: #000088;">$white</span> <span style="color: #339933;">=</span> imagecolorallocate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$black</span> <span style="color: #339933;">=</span> imagecolorallocate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//set the background to white</span>
imagefilledrectangle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$white</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//write name in black</span>
imagestring<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//output header and generate image</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: image/png&quot;</span><span style="color: #009900;">&#41;</span>;
imagepng<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Implementing the Script</h2>
<p>After you have uploaded the above script to your server as disguise_text.php, insert the following image tag into the page you want to display the image (paste onto one line &#8211; it is separated due to column width):</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;img src=&quot;http://www.ebrueggeman.com/blog/wp-admin/disguise_text.php?
text=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="">'jwaters@apple.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 
alt=&quot;email address&quot; /&gt;</pre></div></div>

<p>Here is what the above code actually generates: <img src="http://www.ebrueggeman.com/includes/disguise_text.php?text=andhdGVyc0BhcHBsZS5jb20%3D" alt="email address" /></p>
<h2>Notes</h2>
<p>Without getting overly complicated, the example we have uses size 2 of PHP&#8217;s default font to display the text. The auto image width feature of the script is based on the width of this particular font with this size. If you are going to change the font, make sure to change the $width_per_char and $height variables to accurately represent your font. Also, as shown above, the script only works for pages with white backgrounds. To display the image with a different color background, change the RGB values of the &#8220;$white = imagecolorallocate($img, 255, 255, 255);&#8221; code to match your background.</p>
<h2>Conclusion</h2>
<p>Generating images in PHP is easy if you know the basics, and hiding text from search engines can be a useful tool. Check out this related article on <a href="http://www.ebrueggeman.com/article_php_image_optimization.php">Image Optimization in PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ebrueggeman.com/blog/hiding-email-addresses-and-names-from-search-engines-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
