ObfuscateEmail
Questions answered by this recipe
How do I protect my email addresses in mailto-links from being harvested by spam robots?
Description
Modifications 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.
Notes
Add 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
Comments
This 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:
mailto: displayname <aname@someplace.com>
mailto: ZooKeeper <guru@gnuzoo.org>
The "greater than" - ">" symbol and the "less than" - "<" symbol get converted to HTML character entity references "<" and ">"
. This makes the email link invalid.
[[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 Also
- ProtectEmail - Email obfuscation
- EProtect - Email obfuscation via ROT13
- DeObMail - Unobtrusive e-mail link (de)obfuscator
Contributors
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.