open-source Notes

Notes of an open-source programmer.
15 May

spam-protect your email address

Here is a little trick, to prevent my email address to be harvested by robots. Those spam robots, crawling the web, search for special characters like the ‘@’ sign and try to collect as many email addresses as possible. If your address is in such a pool of collected addresses you will receive many spam mails at this account. To prevent this you can create a picture with your address and display this on your website. Only real living visitors can send you mail but an easy copy&paste is not possible. But there is another approach to this problem. It seems that spam robots do not search for ASCII coded addresses, so you just have to convert your address into HTML conform ASCII values. This is fairly easy with the help of PHP. Here is the worker function:

// Converts a string into ASCII coded html entities
function convert2ASCII($clear){
  $cipher = '';
  for($i=0; $i < strlen($clear); $i++) {
      $cipher .= '&#' . ord(substr($clear, $i, 1));
  }
  return $cipher;
}

But that’s not all. You’ll also need a form to input a string, some PHP code to retrieve the string and some HTML code to display the ASCII coded address. This is the PHP part I use:

$linktext = $mailto = '';
if (isset($_POST['cipher']) || isset($_POST['example'])) {
  $linktext = $_POST['linktext'] ? $_POST['linktext'] : '';
  $mailto = $_POST['mailto'] ? $_POST['mailto'] : '';
  if (isset($_POST['example'])) {
    $linktext = 'linktext';
    $mailto = 'ano@nymo.us';
  }

  $cipher_linktext = convert2ASCII($linktext);
  $cipher_mailto =convert2ASCII($mailto);

  if ($cipher_linktext == '') $cipher_linktext = $cipher_mailto;
  $cipher_string = $cipher_linktext;

  if (strstr($mailto, '@')) {
    $cipher_string = ''.$cipher_linktext.'';
  }
}

Leave a Reply

© 2010 open-source Notes | Entries (RSS) and Comments (RSS)

GPS Reviews and news from GPS Gazettewordpress logo