Protecting email addresses from spam bots

Publishing an email address on the internet now days means a flurry of spam from every spam bot that can get to your site. There are several reasons why small businesses want and need an email address or at least a link to an email address on their sites. But how do we as the developers handle this dilemma?There are three basic methods I like to use depending on the situation, JavaScript, JavaScript and ColdFusion and just ColdFusion.

Javascript

This simple method will cloak the email address from bots by appending the @ symbol and the sites domain to the end of the username passed to the function. The function will also handle firing the mailto link making the html link look like an ordinary link.

<script language="JavaScript">
function noSpm(u){
var domainArry=document.domain.split('.');
var mydomain=document.domain;
if(domainArry.length >= 3){
mydomain=domainArry[1] + '.' + domainArry[2];
}
window.location='mailto:' + u + '@' + mydomain;
}
</script>

<a href="#" onclick="noSpm('username');return false;">Email</a>

JavaScript and ColdFusion

For this method we use ColdFusion to encrypt our email address using a low level encryption method called rot13. Then JavaScript is used to decrypt and handle firing the mailto link. This actually looks like and email address to the bot but not one that will ever return vaild unless decrypted on the client side.

<cfscript>
function rot13(string){
var i=0;
var j=0;
var k=0;
var out="";
for (i=1; i LTE Len(String); i=i+1){
j=Asc(Mid(string, i, 1));
if(j GTE 65 AND j LTE 90){
j=((J-52) MOD 26)+65;
}else if(j GTE 97 AND j LTE 122){
j=((j-84) MOD 26)+97;
}
out=out&Chr(j);
}
return out;
}
</cfscript>

<script language="JavaScript">
var rot13map;

function rot13init(){
var map = new Array();
var s = "abcdefghijklmnopqrstuvwxyz";

for (i=0; i<s.length; i++)
map[s.charAt(i)] = s.charAt((i+13)%26);
for (i=0; i<s.length; i++)
map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
return map;
}

function rot13(a){
if (!rot13map)
rot13map=rot13init();
s = "";
for (i=0; i<a.length; i++)
{
var b = a.charAt(i);

s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
}
return s;
}

function rot_decode(anchor) {
var href = anchor.getAttribute('href');
var address = rot13(href)
if (href != address) {
window.location='mailto:' + address;
}
}
</script>

<cfoutput>
<a href=”#rot13('user@yourdomain.com')# onclick="rot_decode(this);return false;" rel="nofollow">Email</a>
</cfoutput>

ColdFusion

Using this method we convert every character in a string to it's HTML equivalent. When rendered by a browser this will look and act like a valid mailto link but when the source code is scanned by a bot it will return the HTML equivalents only and no valid e-mail address.

<cfscript>
function htmlchr(string){
var newstring='';
for (i=1; i LTE Len(String); i=i+1){
newstring=newstring & "&##" & Asc(Mid(string, i, 1)) & ";";
}
return newstring;
}
</cfscript>

<cfoutput>
<a href=”mailto:#htmlchr('user@yourdomain.com')#”>#htmlchr('user@yourdomain.com')#</a>
</cfoutput>
[Home]    [Company]    [Portfolio]    [Services: [Hosting Services]   ]   [Blog]    [Contact] Follow us on facebook Follow us on Linkedin

Se3 WEB Services is a company offering  

hosting services

Se3 WEB Services an Erie PA based company offering website development, website design Hosting and IT Services, Breaking the Boundaries of Web Development
Se3 WEB Services is an Erie PA based company offering website development, website design Hosting and IT Services
 
 
 
 
Se3 WEB Services is an Erie PA based company offering website development, website design Hosting and IT Services