Categorized | News

Reduce spam with simple function

Posted on 02 August 2002 by Demian Turner

Have you noticed an alarming increase in the amount of spam you\’ve been receiving in the last 6 months? Part of the reason could be you\’ve fallen victim to the droves of email harvesting bots that scour the web.

What\’s the solution? Email obfuscation – use the following simple function to protect your email address so it becomes unreadable to the bots but still looks fine to humans:

function emailObfusc($email) {
$encoded = bin2hex($email);
$encoded = chunk_split($encoded, 2, \’%\’);
$encoded = \’%\’ . substr($encoded, 0, strlen($encoded) – 1);
return $encoded;
}

Bookmark and Share

8 Comments For This Post

  1. Anonymous Says:

    I understand the concept of how the escape work, and how the routine works to get the output… so why doesn\’t it show up as text when I implement it?

    $email2 = emailObfusc($email);
    echo \"$email2\";

    output is
    %6a%61%6d%67%69%6e%65%40%79%61%68%6f%6f%2e%63%6f%6d

    jamgine AT yahoo.com

  2. Anonymous Says:

    that\’s the correct output ! use it in your email link as you normally would, like:

    <a href=\"mailto:%77%65%62%6d%61%73%74%65%72%40%70%68%70%6b%69%74%63%68%65%6e%2e%63%6f%6d\">feedback</a>

    when viewed in a browser it will display a human readable email link :-)

    for proof view the source of this page, completely at the bottom; this technique is used to display the webmaster\’s address.

  3. Anonymous Says:

    Doh!

    Okay, I just set it up and the link info does show the escaped text! way cool… I have a website mod ahead of me tonight.

    My test response to the mailto: hasn\’t hit my server yet, though. Which may be a Yahoo thing, or it may be something else. Can an obfuscated e-mail address be used in a mailto: link?

    Amgine

  4. Anonymous Says:

    absolutely, as I pointed out in the last comment, the obfusc function is used at the bottom of every page in this site for the webmaster mailto link. View source and search for \’feedback\’.

  5. Amgine Says:

    Yes, found my test e-mail this morning, and did the view source… My work last night didn\’t work quite so nicely, but I\’ll be back at it soon. I\’ll also be suggesting this as an element for the user module on the project (phpWebSite), if that\’s okay with you.

    How should I credit this in my source code?

    Amgine

  6. demian Says:

    Thanks Amagine, but there\’s no need for credit – I grabbed this myself I can\’t even remember from where 😉

  7. Anonymous Says:

    being new to php, i\’m not knowing how to use this code snippet, could
    anyone walk me through it please?

  8. Anonymous Says:

    This code does not prevent harvesters from getting the address. The hex coding is easily converted back to text and the address is harvested.

    Stan Rambin

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook