1. What is it?
A PHP function to protect the E-mail address you publish on your website against bots or spiders that index or harvest E-mail addresses for sending you spam. It uses a substitution cipher with a different key for every page load. Look at the generated XHTML in the example while pressing the browsers “reload” button to see this in effect.
2. How does it work?
<?php echo hide_email('email@example.com'); ?>
This is the PHP code you write where you want the E-mail address on your web page.
This is what the E-mail address will look like for the visitor of your web page.
This is the generated XHTML that the bot or spider will see instead of your E-mail address.
4. The code
The “hide_email()” PHP function is only 9 lines of code:
License: Public domain.
5. XHTML generator
You can use this generator if you have no PHP support on your web server. Change the E-mail address into your own E-mail address and press “Generate”. Cut and paste the generated XHTML into your own web page.
- HTML generator by Tim Williams (University of Arizona)
- Improved HTML generator by Andrew Moulden (Site Engineering Ltd.)
- PHP version by Ross Killen (Celtic Productions Ltd.)
- If this script gets very popular bots and spiders might get taught decoding it.
- Line 7 of the PHP code complicates decoding (due to “eval”), but can be left out.
- The main reason for not adding much more complexity is wanting few lines of code.
- I chose the “span” tag over the semantically more correct “noscript” tag;
the XHTML 1.0 strict schema says the “noscript” tag may only contain “Block” elements.