By Debugged Interactive Designs (debuggeddesigns)
Why would I want to use encoded "mailto:" anchor tags? To obfuscate e-mail addresses from spam harvesters. The helper lets you easily encode an entire anchor tag using ROT13 Encryption. The ROT13 encoding simply shifts every letter by 13 places in the alphabet while leaving non-alpha characters untouched. At run-time, javascript is used to decode the ROT13 encryption. If javascript is disabled, then the e-mail address is safely shown by reversing the e-mail address using PHP and re-reversing (versing?) it at run-time using CSS.
Step 1: Create the Mailto helper
This helper's function accepts an e-mail address and link content as it's parameters and returns javascript code containing the encrypted anchor tag.
Filename: /app/views/helpers/mailto.php
Helper Class:
class MailtoHelper extends Helper {
function createLink($addr, $link_content) {
//build the mailto link
$unencrypted_link = ''.$link_content.'';
//build this for people with js turned off
$noscript_link = '';
//put them together and encrypt
$encrypted_link = ''.$noscript_link;
return $encrypted_link;
}
}
?>
Step 2: Include the helper inside your controller
Filename: /app/controllers/tests_controller.php
Controller Class:
class TestsController extends AppController {
var $name = 'Tests';
var $helpers = array('Mailto');
function mailto() { }
}
?>
Step 3: Create the javascript
The javascript decodes the anchor tag that was encoded in the helper above.
Download this file: http://scott.yang.id.au/file/js/rot13.js
Save the file here: /app/webroot/js/rot13.js
Step 4: Include rot13.js in your layout view
Filename: /app/views/layouts/default.thtml
View Template:
Step 5: Use the helper inside a view
Filename: /app/views/tests/mailto.thtml
View Template:
createLink('spam@debuggeddesigns.com','Debugged Interactive Designs'); ?>
Step 6: View the source and be amazed
To test it out, visit the page www.yourdomain.com/tests/mailto
This is the ROT13 encoded anchor tag found in the source code:
I got this idea from a presentation by Mark Rosenthal at a BostonPHP meeting that explained this technique. He admitted that there are many different techniques for tricking spam bots, and he might not be the first to think of this one. Well, after some google searching, he wasn't: http://scott.yang.id.au/2003/06/obfuscate-email-address-with-javascript-rot13/. Believe it or not, that javascript file above was written by Scott Yang in 2003 for this exact purpose. Please leave any alternate techniques you might use in the comments below.
Update: Since creating this helper, I found the article "Nine Ways To Obfuscate E-mail Addresses Compared" at http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/, which says ROT13 encoding and changing the code direction with css "...are absolutely rock-solid and keep your addresses safe from the harvesters."
Friday, November 21, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
hermes
are a allotment of the a lot of absolute hermes watch
in the world. In adjustment to advice you determine, whether the banker is affairs affected Hermes Jewellery
.lida
therapy is normally advised to get consumed early during the morning. Ephedra was acclimated by lots of accepted lida daidaihua
articles aback in the day. daidaihua
is based on ancient Chinese formula. The lida slimming
stick to the basic theme. slimming capsule
is purely natural as it is made from plants no acids. slimming capsules
burns our fat naturally.
A aberration of the aboriginal Coco Chanel backpack is the tweed chanel watches
. However, you will accept to absorb Chanel bags
of dollars adorable your adult with Chanel bag
.Tiffany jewellery
is beautiful if they are used as memories or not. The silver earrings
designs are timeless. Tiffany necklaces
drew upon his love of nature for his original designs, silver necklaces
saw the opportunity to take his beautiful stained glass creations and offer them in a functional art object.
Post a Comment