Effective method to hide email from spam bots

2019-01-02 16:23发布

On my homepage, I'm using this method to hide my email from spam bots:

<a href="admin [at] example.com"
   rel="nofollow"
   onclick="this.href='mailto:' + 'admin' + '@' + 'example.com'">Contact me</a>

What do you think about it? Is it effective? What other methods do you know or use?

30条回答
时光乱了年华
2楼-- · 2019-01-02 17:19

I don't like JavaScript and HTML to be mixed, that's why I use this solution. It works fine for me, for now.

Idea: you could make it more complicated by providing encrypted information in the data-attributes and decrypt it within the JS. This is simply done by replacing letters or just reversing them.

HTML:

<span class="generate-email" data-part1="john" data-part2="gmail" data-part3="com">placeholder</span>

JS:

$(function() {
    $('.generate-email').each(function() {
        var that = $(this);
        that.html(
            that.data('part1') + '@' + that.data('part2') + '.' + that.data('part3')
        );
    });  
});

Try it: http://jsfiddle.net/x6g9L817/

查看更多
呛了眼睛熬了心
3楼-- · 2019-01-02 17:20

Here is my working version:


Create somewhere a container with a fallback text:

<div id="knock_knock">Activate JavaScript, please.</div>

And add at the bottom of the DOM (w.r.t. the rendering) the following snippet:

<script>
  (function(d,id,lhs,rhs){
    d.getElementById(id).innerHTML = "<a rel=\"nofollow\" href=\"mailto"+":"+lhs+"@"+rhs+"\">"+"Mail"+"<\/a>";
  })(window.document, "knock_knock", "your.name", "example.com");
</script>

It adds the generated hyperlink to the specified container:

<div id="knock_knock"><a rel="nofollow" href="your.name@example.com">Mail</a></div>

In addition here is a minified version:

<script>(function(d,i,l,r){d.getElementById(i).innerHTML="<a rel=\"nofollow\" href=\"mailto"+":"+l+"@"+r+"\">"+"Mail"+"<\/a>";})(window.document,"knock_knock","your.name","example.com");</script>
查看更多
怪性笑人.
4楼-- · 2019-01-02 17:25

There are probably bots that recognize the [at] and other disguises as @ symbol. So this is not a really effective method.

Sure you could use some encodings like URL encode or HTML character references (or both):

// PHP example
// encodes every character using URL encoding (%hh)
function foo($str) {
    $retVal = '';
    $length = strlen($str);
    for ($i=0; $i<$length; $i++) $retVal.=sprintf('%%%X', ord($str[$i]));
    return $retVal;
}
// encodes every character into HTML character references (&#xhh;)
function bar($str) {
    $retVal = '';
    $length = strlen($str);
    for ($i=0; $i<$length; $i++) $retVal.=sprintf('&#x%X;', ord($str[$i]));
    return $retVal;
}

$email = 'user@example.com';
echo '<a href="'.bar('mailto:?to=' . foo(','.$email.'')).'">mail me</a>';

// output
// <a href="&#x6D;&#x61;&#x69;&#x6C;&#x74;&#x6F;&#x3A;&#x3F;&#x74;&#x6F;&#x3D;&#x25;&#x32;&#x43;&#x25;&#x37;&#x35;&#x25;&#x37;&#x33;&#x25;&#x36;&#x35;&#x25;&#x37;&#x32;&#x25;&#x34;&#x30;&#x25;&#x36;&#x35;&#x25;&#x37;&#x38;&#x25;&#x36;&#x31;&#x25;&#x36;&#x44;&#x25;&#x37;&#x30;&#x25;&#x36;&#x43;&#x25;&#x36;&#x35;&#x25;&#x32;&#x45;&#x25;&#x36;&#x33;&#x25;&#x36;&#x46;&#x25;&#x36;&#x44;">mail me</a>

But as it is legal to use them, every browser/e-mail client should handle these encodings too.

查看更多
梦寄多情
5楼-- · 2019-01-02 17:25

I like ofaurax's answer best but I would modify to this for a little more hidden email:

onclick="p1='admin'; p2='domain.com'; this.href='mailto:' + p1 + '& #x40;' + p2"
查看更多
无色无味的生活
6楼-- · 2019-01-02 17:27

Have a look at this way, pretty clever and using css.

CSS

span.reverse {
  unicode-bidi: bidi-override;
  direction: rtl;
}

HTML

<span class="reverse">moc.rehtrebttam@retsambew</span>

The CSS above will then override the reading direction and present the text to the user in the correct order.

Hope it helps

Cheers

查看更多
弹指情弦暗扣
7楼-- · 2019-01-02 17:28

And my function. I've created it looking at answers placed in this topic.

 function antiboteEmail($email)
 {
        $html = '';

        $email = strrev($email);
        $randId = rand(1, 500);

        $html .= '<span id="addr-'.$randId.'" class="addr">[turn javascript on to see the e-mail]</span>';
        $html .= <<<EOD
                <script>
                $(document).ready(function(){

                    var addr = "$email";
                    addr = addr.split("").reverse().join("");
                    $("#addr-$randId").html("<a href=\"mailto:" + addr + "\">" + addr + " </a>");
                });
                </script>
EOD;

        return $html;
    }

It uses two methods: right to left dir and javascript putting.

查看更多
登录 后发表回答