Automatic Email Address Protection PHP / JavaScript

Date: 27th October 2008 at 7:44 pm | Filed under: development, scripts | Author: Sam Burdge

It is important to protect email addresses on websites from being harvested by spambots.

"Email spambots collect e-mail addresses from the Internet in order to build mailing lists for sending unsolicited e-mail, also known as spam. Such spambots are web crawlers that can gather e-mail addresses from Web sites, newsgroups, special-interest group (SIG) postings, and chat-room conversations. Because e-mail addresses have a distinctive format, spambots are easy to write. A number of legislators in the U.S. are reported to be devising laws that would outlaw the spambot." – Wikipedia

This is my method for automatically detecting email addresses and replacing them with a javascript that will disguise them from spambots. The script works in two stages one in javascript and the other in php.

First the javascript function that outputs the mailto link:

function sb_email(user,site){
document.write('<a href=\"mailto:' + user + '@' + site + '\">');
document.write(user + '@' + site + '<\/a>');
}

The function has 2 parameters "user" and "site", which are the two parts of the email address either side of the "@". This function can be called like so:

sb_email('joe','bloggs.com');

The second part is the php functions that recognise email addresses and replace them with the javascript function to disguise them:

//function to output the js
function create_js ($matches){
$parts = explode ('@', substr ($matches[0], 1));
if(substr($parts[1],-1)=='.'){$parts[1]=substr($parts[1],0,-1); $parts[2]='.';}
$str = $matches[1].'<script language="JavaScript" type="text/javascript">';
$str .= 'sb_email("'.$parts[0].'", "'.$parts[1].'");';
$str .= '</script>'.$parts[2];
return $str;
}
$js_callback = "create_js ";
 
//function to recognise emails
function email_protect($text){
global $js_callback;
$replace = '/([> ])[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}/i';
$output = preg_replace_callback($replace, $js_callback, $text);
return $output;
}

The email_protect php function can be called on any text string like so:

echo email_protect($text);

It will automatically replace any email addresses in the text with the javascript, therefore hiding them from spambots.

Leave a Comment

Leona Naess animated logo and holding page

Date: 15th August 2008 at 10:19 am | Filed under: flash, portfolio | Author: Sam Burdge

This holding page built for Polydor artist, singer / songwriter Leona Naess features an animated logo with random fades and glows. The flash random timing actionscript is something I have utilised in the past to create similar effects (see: Flash mousetrails with random flashes!).

The holding page also features a streaming mp3 (using flash), mailing list signup form with javascript validation embedded youtube video and google analytics.

Check it out:

www.leonanaess.com

Leave a Comment

Heathcote Bailey Website

Date: 7th June 2008 at 11:19 pm | Filed under: portfolio | Author: Sam Burdge

hbscreen1 hbscreen2

Heathcote Bailey is a creatively led events services company specialising in bespoke party production. The site is built in a combination of PHP, JavaScript and HTML. It features a large scrolling background image which is very cool.

Check it out: www.heathcotebailey.co.uk

Leave a Comment

Flash - random motion and rotation - Actionscript 2

Date: 9th April 2008 at 11:32 am | Filed under: actionscript, development, flash | Author: Sam Burdge

Back again, my pet tadpoles (they still haven't grown into frogs yet!). This time I am going to explain the actionscript that makes them move, turn and run from the mouse. Firstly, heres an example of what they do (move your mouse over them and watch 'em swim away): Read on…

4 Responses to “Flash - random motion and rotation - Actionscript 2”

  • Comment by Sherry
    Date: April 9th, 2008 at 5:14 pm

    This is very cool, thank you for sharing. I can't wait to try it :-)

  • Comment by sherry
    Date: April 10th, 2008 at 8:55 pm

    Hi, I tried this out and am having trouble getting it to work. Am I supposed to have 2 different layers, one for tadpole and one for mouse_mc? Also, my transparent pixels don't seem to be attached to my mouse…

  • Comment by Sam Burdge
    Date: April 12th, 2008 at 11:04 pm

    Hi Sherry

    They can be on separate layers, or both the same layer, it shouldn’t matter. Did you give the movie clips instance names in the ‘properties’ panel?

    Sam

  • Comment by bex
    Date: August 12th, 2008 at 2:10 pm

    Hi there, just wondering if you’d have an tips on converting this to AS3. I’m very new to Flash and have been trying to do it all day!

    Thanks in advance,

    bex.

Leave a Comment

Image mouseovers without javascript - CSS & Sprites

Date: 3rd March 2008 at 1:27 am | Filed under: development, scripts | Author: Sam Burdge

This article is an extension / improvement upon another article I published on my site previously: Simple Javascript for Image Mouseovers. As I am always looking for improved methods, I was discussing the pitfalls of the javascript method with a friend (and occasional comment writer / contributor to my site) who pointed me in the direction of CSS and image sprites. This lead me to research the topic further, and I found two articles in particular which were incredibly useful:

Read on…

2 Responses to “Image mouseovers without javascript - CSS & Sprites”

Leave a Comment