PhpRiot
Download This Article
Download this article or the entire “Anti-Spam Techniques In PHP” series with all listings and files.




More information
Related Articles
Related Books
Smarty PHP Template Programming And Applications

Smarty PHP Template Programming And Applications

Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (11), JSON (2), MVC (1), MySQL (6), onbeforeunload (1), OOP (1), PHP (27), PhpDoc (1), PostgreSQL (6), Prototype (10), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Anti-Spam Techniques In PHP, Part 1

Technique 2: Rewriting

This technique is used commonly by people who post to forums, blogs or discussions to keep their email address human-readable, but without using standard symbols like @ and period. This means if anyone wants to email you they will have to type out your email address manually, but at least if somebody has gone to that effort it’s unlikely they are sending you spam.

So basically what we are doing here is to turn an email address that looks like antispam@example.com into antispam [AT] example [DOT] com, or something along those lines.

Once again, Smarty has built in functionality for this, once again using the escape modifier.

Listing 4 listing-4.tpl
{assign var='email' value='antispam@example.com'}
{$email|escape:'mail'}

This will output

Listing 5 Output from using Smarty's email address escaping (listing-5.txt)
antispam [AT] example [DOT] com

There’s no point in making this a hyperlink as it would not be valid anyway.

To achieve this without Smarty, use something like this:

Listing 6 listing-6.php
<?php
    function escapeEmail($string)
    {
        return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
    }
 
    $email = 'antispam@example.com';
    echo escapeEmail($string);
?>

A further technique you could employ is to use random replacements for multiple email address, so each time you show an address it could be different, like antispam [AT] example [DOT] com, then antispam AT example DOT com, just simple variations like that which make harvester writers have to work that extra bit harder.

In This Article


Tagged in ,