|
Cookbook /
ObfuscateEmailSummary: Prevent email addresses from being harvested from your site
Version: 1.0
Prerequisites: none
Status:
Maintainer: Jari Vanha-Eskola jari.vanha-eskola@eduweb.fi
Questions answered by this recipeHow do I protect my email addresses in mailto-links from being harvested by spam robots? DescriptionModifications to obfuscate email addresses so that they are not displayed in plain text to robots. Script recreates link text as character encoded, thus mailto:spam@nospam.com becomes mailto:spa...m Does not require JavaScript or any other special techniques, works in every browser and client device. NotesAdd the following code to your local/config.php and you're all set!
## obfuscate mailto-links
$LinkFunctions['mailto:'] = 'myLinkIMap';
## $IMapLinkFmt['mailto:'] = "<a class=\"urllink\" href=\"\$LinkUrl\">\$LinkText</a>";
function myLinkIMap($pagename,$imap,$path,$title,$txt,$fmt=NULL) {
if ($txt{0}=='&') return LinkIMap($pagename,$imap,$path,$title,$txt,$fmt);
global $FmtV, $IMap, $IMapLinkFmt, $UrlLinkFmt;
$FmtV['$LinkUrl'] = obfuscate(PUE(str_replace('$1',$path,$IMap[$imap])));
$FmtV['$LinkText'] = obfuscate($txt);
$FmtV['$LinkAlt'] = str_replace(array('"',"'"),array('"','''),$title);
if (!$fmt)
$fmt = (isset($IMapLinkFmt[$imap])) ? $IMapLinkFmt[$imap] : $UrlLinkFmt;
return str_replace(array_keys($FmtV),array_values($FmtV),$fmt);
}
function obfuscate($s) {
$r = '';
for ($i=0;$i<strlen($s);$i++) {
$r = $r . ( ($s{$i}==':') ? ':' : sprintf('&#%03d;', ord($s{$i})) );
}
return $r;
}
Release Notes
CommentsThis does obfuscate the email address in the source code. It looks like it will work, except that it goofs up when the email address has a "display name" in it. The email address format (see paragraph 4 of this link)) is:
The "greater than" - ">" symbol and the "less than" - "<" symbol get converted to HTML character entity references
[[mailto:username@domain | The_name_you_want_displayed]]
instead of html/email syntax. For example:
[[mailto:guru@gnuzoo.org | ZooKeeper]]
Nice but ...Sadly it is probably not enough to protect from harvesters, I tested the solution with http://aspirine.org/cgi-bin/trouvemail.pl?lang=en and it fell under poor encoding. rot13 used by the other solutions is also not enough -Damien September 28, 2008, at 04:54 PM See AlsoContributors |