...rollover me and I'll toogle for you 

You are surfing Manakor Coding Map TMHope you are keen on this useful tips & tricks. Thank you for staying in touch.
Just continue to collaborate and enjoy!

Portfolio of Nikita SumeikoProfessional Front End Web Developer

The best way to hide email address from spyders and bots

In today’s world almost every website is based on powerful CMS system, where it’s administrator is able to edit website’s main content on the fly. Often this ability drives into an unlikely email address publications, which brings a lot of spam to a website’s owners.
Therefore, to fight against spam I do offer to hide all the email addresses on every website’s page in handsome and clear way. From one side, this would help us to avoid spiders, which catches all the open to public email addresses. But from the other side, this technique would bring our email address to real visitors.

Playing on the server side

As is well known, the greater part of email spiders (robots) surfs every website’s code, looking for email addresses and saves them. That is why I offer to find and replace every email address, which has been loaded as a single text or mailto hyperlink before spider will see it. The fastest way is by using PHP server side scripting.

First of all, we are going to write a function to use all over our website. The main purpose of this function is to find all the published email addresses and replace them into specific, but very useful format (example AT example DOT com). In this function we’ll use PHP Regular expressions to find all the necessary formats and some basic PHP function to rewrite them properly. By this way we hide all our emails on the server side and web spiders, bots, which catches emails, will get nothing at all.

Start to code a function

So, let’s start with the function coding:

// function which replaces mailto links into specific format
function tep_rewrite_email($content) {

  // function rules will go here

}
Include the right format email pattern

Inside this function we are going to include some variables, which will help us to do the job. And the first one is regex email pattern, which is written in a specific format to use further. Drop an eye on NetTuts+ Regular Expressions Complete Guide and than move forward to the code below:

// regex email address pattern, format (\\1)@(\\2).(\\3)
$email_pattern = '([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z0-9._%-]+)';
Add standard mailto link pattern

Than we add standart html mailto link pattern, which will match all the mailto links. Moreover, this pattern is flexible, and that is why it will not skip any real link which contains ‘mailto:’ expression:

  // pattern for html links: <a href="mailto: example@exmaple.com">Some other text</a>
  // attributes before and after 'href' do not interfere
  $mailto_pattern = '#\]*?href=\"mailto:\s?' . $email_pattern . '[^>]*?\>[^>]*?<\/a\>#';
Set up a result you need to get

And the last variable to add is the result, which we finally would like to get. It’s specific (example AT example DOT com), but very usefull to avoid any spider. Have a look:

  // rewrtite result
  $rewrite_result = '\\1 AT \\2 DOT \\3';
Find and replace is simple

When variables are completely added, we are going to use simple PHP functions to find and replace necessary content. I’d like to remeber, that emails can be published in two ways – as a mailto link and as a simple emails address. Therefore we check webpage’s content two times. Let’s see the code below:

  // firstly, look for html mailto links and replace them
  $content = preg_replace($mailto_pattern, $rewrite_result, $content);

  // secondly, find stacionary emails without links and replace them too
  $content = preg_replace('#' . $email_pattern . '#', $rewrite_result, $content);

As you see, PHP preg_replace function is looking for our mailto link and email patterns and replace them completely by outputting a necessary result.

I will repeat again, that we need such a specific format (example AT example DOT com) for 2 aims:

  1. To avoid spiders looking for a fresh emails to catch inside your page’s source code
  2. To revert it back into clear, valid and visible format for real visitors, not bots
PHP function which is ready to work for you

Now, when every component of a function is ready, let’s group them all:

  function tep_rewrite_email($content) {
    $email_pattern = '([A-Za-z0-9._%-]+)\@([A-Za-z0-9._%-]+)\.([A-Za-z0-9._%-]+)';
    $mailto_pattern = '#\]*?href=\"mailto:\s?' . $email_pattern . '[^>]*?\>[^>]*?<\/a\>#';
    $rewrite_result = '\\1 AT \\2 DOT \\3';

    $content = preg_replace($mailto_pattern, $rewrite_result, $content);
    $content = preg_replace('#' . $email_pattern . '#', $rewrite_result, $content);

    // remember to add return here
    return $content;
  }

Finally, we get a wonderful and necessary result in our source code. The image below show how does the code looks like:

JQuery or what can be simpler?!

When all the single text or mailto hyperlink email addresses have been rewritten to a new format, we are going to turn them back into valid links by using JQuery, which provides client side scripting and works with all the major browsers. I think the best way here would be to use HTML-Advisor method. However, there are different ways to do it.

But first of all, you should know the fastest way how to implement JQuery into your page. Read about 10 Ways to Instantly Increase Your jQuery Performance.

I’d like to note, that JavaScript is a clients side language, therefore it provides us an ability to make code modifications directly in a visitor browser. And our aim here is to workout a simple function, which will find prepared email format and replace it back into a visible and understandable links to the audience.

So, let’s get down to the code by understanding each peace.

Check if the necessary element exists
  // check if our pre-made class exists on a page
  if ( $("span.mailme").length ) {

	// variables and function will be there

  }

JQuery code posted above check if there’re any <span class=”mailme”> on the page

Set up variables
  var at = / AT /; // pattern for AT letters
  var dot = / DOT /g; // pattern for DOT letter
Replace them all on-the-fly

Than we code a function, which adds mailto link into our prepared content and replaces AT and DOT letters with ‘@’ and ‘.’ appropriately:

  // function, which replaces pre-made class
  $('span.mailme').each(function () {
    var addr = $(this).text().replace(at, '@').replace(dot, '.');
    $(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
    $(this).remove();
  });
The final JQuery function

Completely our JQuery code should look like this:

if ( $("span.mailme").length ) {// variables, which will be replaced
  var at = / AT /;
  var dot = / DOT /g;

  // function, which replaces pre-made class
  $('span.mailme').each(function () {
    var addr = $(this).text().replace(at, '@').replace(dot, '.');
    $(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
    $(this).remove();
  });
}

As you see we have made some modification to the clients side. As a result every website visitor will see published emails as a normal links, but email spiders won’t have a dinner this night.

Modifications to the output

The last we should make, is to modificate our webpages output. I mean to find out where our CMS outputs each page’s body text (which may consist email addresses) and replace it with our premade PHP function:


  // find a string which outputs every page body text from your database
  $string = 'Our company is based in London and we bring strong metallic structures to the world. Our experience are wide and stable. To get more information about products we offer, contact sales department by email: <a href="mailto: sales@company.com" title="Sales">sales@company.com</a>. And to offer sponsorship email directly to Lisa: lisa@company.com';
  $string = tep_rewrite_email($string);

What we get is what we have made

All in all, we get a quite simple result, which will be never cathed by email spiders. And our real website’s audience would see all the published email addresses as normal. By implementing this technique into each new page you are going to build, you will stay sure, that email addresses are hiden and spam is in the past.

I see this technique very useful for every website, which is updating by persons who don’t know how to keep an email address safe. It goes very well with different CMS systems and can be implemented in a simple way.

The “free” distribution of unwelcome or misleading messages to thousands of people is an annoying and sometimes destructive use of the Internet’s unprecedented efficiency.
Bill Gates, New York Times, 1998

Comments line (5)
  1. [...] Read the original here: The best way to hide email address from spyders and bots | Manakor … [...]

  2. [...] reading here: The best way to hide email address from spyders and bots | Manakor … [...]

  3. [...] This post was mentioned on Twitter by nettuts: The best way to hide an email address from bots: http://www.manakor.org/the-bes.....om-spyders [...]

  4. [...] The best way to hide email address from spyders and bots | Manakor Coding Map™ [...]

  5. [...] reading here: The best way to hide email address from spyders and bots | Manakor Coding Map™ Tags: cloak, hide, spam, [...]

Post your comment

* Fill in the first, second and the last field to activate the button!

« small navigation between posts »
Subscribe and Bookmarkmaturetube.com
youporne
shush tube.com
celebboobtube
dirtytube porn
uporntube.com
spanking tube
shocking tube
tubexxx
utube porn
studded tube manufacturers
porntube sites
8 tube porn
xxxtube
gexo x tube
peg tube perferation
milftube
rtube
tubeteenscom
lubetube
z pornotube
pussy tube
one tube oscillators
zootube
8 tube
p tube
pinktube
re tube ps
poh tube
tube xxx
tube top
tou tube
twinksxtubeporn
xtube spy college
tube.com
tuberose essential oil
filthtube
extreme tube porn
zootube 365
pronotube
vacuum tubes
tree tube
redporntube
foot fetish tube
skimtube
free tube porn
bizarre tube porn
tivias tube
germany porn tube
tittube
mature tube
sex tube sites
porno tube xxx
tube sexy
fktubecom
beasttube
snake tube xxx
homemoviestube.com
pornotube
my tube
croctube
www red tubecom
sextube.com
porno tube beta
incest porn tube
free sextube
freedomtube
bondage and tube
yutube glasba
x tube.com
iyottube
redtube
xtube sport boys
xnxx
tubehentai.com
tube tube
xtube rom
zootube
zoo sex tube 365
adult tube movies
tiava s tube
reded tube
dancing xtube
free porn tubes
nikki blond file tube
sex porn tube
yuvutube
sextube videos
bestiality zootube 365
yu tube sexs
download redtube videos
red tube videos
zoo tube
amateur tube
nudetubecom
porn movie tube
animalporn tube
tube for porn
zootube365
xtube.com/matthewlush
tiavas tube
tuberculosis
pornotube.com acount
porn utube8
pornhube
hq tube
ebonytube
test tubes
amateur asian creampies red tube
yuo tube porno
twin fuck tube
reedtube
yoytube
teen tube
shemale tubes
asian porn tube
beastube
grannytube
redtube.com porn
4tube
xtube gay
japanese porntube
zootube.co.uk
xtube nudist beach
famouspornstarstube.com
r tube
gaytube
rockettube.com
panty pissing xtube
hot tube
hardsextube
enemas utube
xtube video
x tube wanking cumming
redtube
u tube nudes
bbw tube
gay tube
red tubecom
girls kissing on utube
jiss tube
zoosex tube
sexytube.com
gay x tube videos
horsetube
beastiality tube
free psp tubes adult
hqtube com
hotutubes
boob tube
saving xtube videos
wanktube
innertube
free extreme pornotube
tube8 videos vote
red tube4
free porn tube.com
bdsm tube
blue tube
hardtube
red porn tube
godtube
lolita undressing tube
free sex porn tube
www.nude tube.com
scat tube
xtube football toilette
adult u tube
tube8.com
cumtube
xtube cumming
redtube eu
hentai tube
xtube ball
redtube competition
nudisten tube
tube videos xxx
dog sex tube
bangtubecom
tubecom
porn tube
zootube.com
gas detection tube
black tube dress
solar bubble tube
download xtube videos free
nudetube
utube enema viedo
rawtube
free web tube porn
panty peeing xtube
sextube
brazzerstube com
rde tube
mammothtube
rude tube
bootytube
sluttube
free porn tube
pornoytube
japanese tits tube
tube 8 bbw
fucktube.com
xtube big brother
lesbian tube
eskimotube
tubegals.com
kick boxing xtube
beast tube xxx horse
xxx porn tube
porn tube8
pornotubexxx
tree tubes
pornhub
ourtube
redtube,com
sextubes
xtube berlin toilette
bang tube
psp sexy tubes
london tube map
zoo animal sex tube
erotic hot tube
lube yor tube
fetishtube
zootube porn
beach xtube
the boob tube
rape tube
zoo tube com
animal sex tube
porn tubes
black porn tubes
tube8 and beastiality
www.tube8.com
free beast tube horse sex
TUBESEX
utube videos
rred tube
uporntube
ass nude tube
jeans pissing xtube
dudetubeonline
yot tube
adult tube
hqtubecom
beast tube xxx
sexy utube
crush fetish tube
animals bestiality tube
Follow and Share Notebook posts categories Twitter Updates What other say about my job