Html 从垃圾邮件机器人隐藏电子邮件的有效方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/483212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:06:04  来源:igfitidea点击:

Effective method to hide email from spam bots

htmlalgorithmemailspam

提问by abatishchev

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?

你怎么看待这件事?它有效吗?您知道或使用哪些其他方法?

回答by Fuhrmanator

This is the method I used, with a server-side include, e.g. <!--#include file="emailObfuscator.include" -->where emailObfuscator.includecontains the following:

这是我使用的方法,带有服务器端包含,例如<!--#include file="emailObfuscator.include" -->其中emailObfuscator.include包含以下内容:

<!-- // http://lists.evolt.org/archive/Week-of-Mon-20040202/154813.html -->
<script type="text/javascript">
    function gen_mail_to_link(lhs,rhs,subject) {
        document.write("<a href=\"mailto");
        document.write(":" + lhs + "@");
        document.write(rhs + "?subject=" + subject + "\">" + lhs + "@" + rhs + "<\/a>");
    }
</script>

To include an address, I use JavaScript:

为了包含地址,我使用 JavaScript:

<script type="text/javascript"> 
    gen_mail_to_link('john.doe','example.com','Feedback about your site...');
</script>
<noscript>
  <em>Email address protected by JavaScript. Activate JavaScript to see the email.</em>
</noscript>

Because I have been getting email via Gmail since 2005, spam is pretty much a non-issue. So, I can't speak of how effective this method is. You might want to read this study(although it's old) that produced this graph:

因为我从 2005 年开始通过 Gmail 接收电子邮件,垃圾邮件几乎不是问题。所以,我不能说这种方法有多有效。您可能想阅读生成此图的这项研究(虽然它很旧):

enter image description here

在此处输入图片说明

回答by cyptus

Working with content and attr in CSS:

在 CSS 中处理 content 和 attr:

.cryptedmail:after {
  content: attr(data-name) "@" attr(data-domain) "." attr(data-tld); 
}
<a href="#" class="cryptedmail"
   data-name="info"
   data-domain="example"
   data-tld="org"
   onclick="window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld; return false;"></a>

When javascript is disabled, just the click event will not work, email is still displayed.

当javascript被禁用时,点击事件将不起作用,电子邮件仍然显示。

Another interesting approach (at least without a click event) would be to make use of the right-to-left mark to override the writing direction. more about this: https://en.wikipedia.org/wiki/Right-to-left_mark

另一种有趣的方法(至少没有点击事件)是利用从右到左的标记来覆盖书写方向。更多相关信息:https: //en.wikipedia.org/wiki/Right-to-left_mark

回答by roundcrisis

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

看看这种方式,非常聪明并且使用 css。

CSS

CSS

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

HTML

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.

然后上面的 CSS 将覆盖阅读方向并以正确的顺序向用户呈现文本。

Hope it helps

希望能帮助到你

Cheers

干杯

回答by tvanfosson

I have a completely different take on this. I use MailHidefor this.

我对此有完全不同的看法。为此,我使用MailHide

MailHide is a system from Google whereby the user needs to complete a reCAPTCHA test to then reveal the email to them.

MailHide 是 Google 的一个系统,用户需要通过该系统完成 reCAPTCHA 测试,然后才能向他们显示电子邮件。

回答by Andrew Swift

Not my idea originally but I can't find the author:

最初不是我的想法,但我找不到作者:

<a href="mailto:[email protected]"
    onmouseover="this.href=this.href.replace(/x/g,'');">link</a>

Add as many x's as you like. It works perfectly to read, copy and paste, and can't be read by a bot.

添加任意数量的 x。它可以完美地读取、复制和粘贴,并且机器人无法读取。

回答by rmeador

I think the only foolproof method you can have is creating a Contact Me page that is a form that submits to a script that sends to your email address. That way, your address is never exposed to the public at all. This may be undesirable for some reason, but I think it's a pretty good solution. It often irks me when I'm forced to copy/paste someone's email address from their site to my mail client and send them a message; I'd rather do it right through a form on their site. Also, this approach allows you to have anonymous comments sent to you, etc. Just be sure to protect your form using some kind of anti-bot scheme, such as a captcha. There are plenty of them discussed here on SO.

我认为您可以拥有的唯一万无一失的方法是创建一个“联系我”页面,该页面是一种提交给脚本的表单,该脚本发送到您的电子邮件地址。这样,您的地址就永远不会向公众公开。由于某种原因,这可能是不可取的,但我认为这是一个很好的解决方案。当我被迫将某人的电子邮件地址从他们的站点复制/粘贴到我的邮件客户端并向他们发送消息时,我经常感到恼火;我宁愿通过他们网站上的表格来做。此外,这种方法允许您向您发送匿名评论等。请务必使用某种反机器人方案(例如验证码)保护您的表单。这里有很多关于 SO 的讨论。

回答by Galwegian

See Making email addresses safe from bots on a webpage?

请参阅使电子邮件地址免受网页上机器人的攻击?

I like the way Facebook and others render an image of your email address.

我喜欢 Facebook 和其他人呈现您的电子邮件地址图像的方式。

I have also used The Enkoderin the past - thought it was very good to be honest!

我过去也使用过Enkoder-老实说,我认为它非常好!

回答by Matias

If you have php support, you can do something like this:

如果你有 php 支持,你可以做这样的事情:

<img src="scriptname.php">

And the scriptname.php:

和脚本名.php:

<?php
header("Content-type: image/png");
// Your email address which will be shown in the image
$email    =    "[email protected]";
$length    =    (strlen($email)*8);
$im = @ImageCreate ($length, 20)
     or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 255, 255, 255); // White: 255,255,255
$text_color = ImageColorAllocate ($im, 55, 103, 122);
imagestring($im, 3,5,2,$email, $text_color);
imagepng ($im);
?>

回答by Jani Hyyti?inen

I know my answer won't be liked by many but please consider the points outlined here before thumbing down.

我知道我的回答不会被很多人喜欢,但请在否决之前考虑这里列出的要点。

Anything easily machine readable will be easily machine readable by the spammers. Even though their actions seem stupid to us, they're not stupid people. They're innovative and resourceful. They do not just use bots to harvest e-mails, they have a plethora of methods at their disposal and in addition to that, they simply pay for good fresh lists of e-mails. What it means is, that they got thousands of black-hat hackers worldwide to execute their jobs. People ready to code malware that scrape the screens of other peoples' browsers which eventually renders any method you're trying to achieve useless. This thread has already been read by 10+ such people and they're laughing at us. Some of them may be even bored to tears to find out we cannot put up a new challenge to them.

任何易于机器读取的内容都将很容易被垃圾邮件发送者机器读取。尽管他们的行为在我们看来很愚蠢,但他们并不是愚蠢的人。他们富有创新精神和足智多谋。他们不只是使用机器人来收集电子邮件,他们还有很多方法可供使用,除此之外,他们只需支付良好的新电子邮件列表即可。这意味着,他们让全球成千上万的黑帽黑客来执行他们的工作。人们准备编写恶意软件,这些恶意软件会抓取其他人的浏览器的屏幕,最终使您试图实现的任何方法都变得毫无用处。这个帖子已经被 10 多个这样的人阅读了,他们在嘲笑我们。他们中的一些人甚至可能会因为发现我们无法向他们提出新的挑战而感到无聊而流泪。

Keep in mind that you're not eventually trying to save your time but the time of others. Because of this, please consider spending some extra time here. There is no easy-to-execute magic bullet that would work. If you work in a company that publishes 100 peoples' e-mails on the site and you can reduce 1 spam e-mail per day per person, we're talking about 36500 spam emails a year. If deleting such e-mail takes 5 seconds on average, we're talking about 50 working hours yearly. Not to mention the reduced amount of annoyance. So, why not spend a few hours on this?

请记住,您最终不是要节省自己的时间,而是要节省他人的时间。因此,请考虑在这里多花一些时间。没有任何易于执行的灵丹妙药可以奏效。如果您在一家在网站上发布 100 人电子邮件的公司工作,并且您可以减少每人每天 1 封垃圾邮件,我们说的是每年 36500 封垃圾邮件。如果删除这样的电子邮件平均需要 5 秒钟,我们说的是每年 50 个工作小时。更不用说减少了烦恼。那么,为什么不花几个小时呢?

It's not only you and the people who receive the e-mail that consider time an asset. Therefore, you must find a way to obfuscate the e-mail addresses in such way, that it doesn't pay off to crack it. If you use some widely used method to obfuscate the e-mails, it really pays off to crack it. Since as an result, the cracker will get their hands on thousands, if not tens or hundreds of thousands of fresh e-mails. And for them, they will get money.

不仅您和收到电子邮件的人都认为时间是一种资产。因此,您必须找到一种以这种方式混淆电子邮件地址的方法,这样破解它就无济于事。如果您使用一些广泛使用的方法来混淆电子邮件,那么破解它确实是值得的。因此,破解者将获得数千、甚至数万或数十万封新电子邮件。对他们来说,他们会得到钱。

So, go ahead and code your own method. This is a rare case where reinventing the wheel really pays off. Use a method that is not machine readable and one which will preferably require some user interaction without sacrificing the user experience.

所以,继续编写你自己的方法。这是一种罕见的情况,重新发明轮子确实有回报。使用一种非机器可读的方法,并且最好在不牺牲用户体验的情况下需要一些用户交互。

I spent some 20 minutes to code off an example of what I mean. In the example, I used KnockoutJS simply because I like it and I know you won't probably use it yourself. But it's irrelevant anyway. It's a custom solution which is not widely used. Cracking it won't pose a reward for doing it since the method of doing it would only work on a single page in the vast internet.

我花了大约 20 分钟来编写一个示例来说明我的意思。在这个例子中,我使用 KnockoutJS 只是因为我喜欢它,而且我知道你自己可能不会使用它。但这无论如何都无关紧要。这是一种未广泛使用的自定义解决方案。破解它不会因为这样做而获得奖励,因为这样做的方法只能在庞大的互联网中的单个页面上工作。

Here's the fiddle: http://jsfiddle.net/hzaw6/

这是小提琴:http: //jsfiddle.net/hzaw6/

The below code is not meant to be an example of good code. But just a quick sample of code which is very hard for machine to figure out we even handle e-mails in here. And even if it could be done, it's not gonna pay off to execute in large scale.

下面的代码并不是好的代码示例。但只是一个快速的代码示例,机器很难弄清楚我们甚至在这里处理电子邮件。即使可以做到,大规模执行也不会有回报。

And yes, I do know it doesn't work on IE = lte8 because of 'Unable to get property 'attributes' of undefined or null reference' but I simply don't care because it's just a demo of method, not actual implementation, and not intended to be used on production as it is. Feel free to code your own which is cooler, technically more solid etc..

是的,我确实知道它在 IE = lte8 上不起作用,因为“无法获取未定义或空引用的属性‘属性’”但我根本不在乎,因为它只是方法的演示,而不是实际实现,并且不打算按原样用于生产。随意编写自己的代码,它更酷,技术上更可靠等。

Oh, and never ever ever name something mail or email in html or javascript. It's just way too easy to scrape the DOM and the window object for anything named mail or email and check if it contains something that matches an e-mail. This is why you don't want any variables ever that would contain e-mail in it's full form and this is also why you want user to interact with the page before you assign such variables. If your javascript object model contains any e-mail addresses on DOM ready state, you're exposing them to the spammers.

哦,永远不要用 html 或 javascript 命名邮件或电子邮件。为任何名为邮件或电子邮件的内容抓取 DOM 和窗口对象并检查它是否包含与电子邮件匹配的内容,这太容易了。这就是为什么您不希望任何变量包含完整形式的电子邮件,这也是您希望用户在分配此类变量之前与页面交互的原因。如果您的 javascript 对象模型包含任何处于 DOM 就绪状态的电子邮件地址,您就是在将它们暴露给垃圾邮件发送者。

The HTML:

HTML:

<div data-bind="foreach: contacts">
    <div class="contact">
        <div>
            <h5 data-bind="text: firstName + ' ' + lastName + ' / ' + department"></h5>
            <ul>
                <li>Phone: <span data-bind="text: phone"></span></li>
                <li><a href="#999" data-bind="click:$root.reveal">E-mail</a> <span data-bind="visible: $root.msgMeToThis() != ''"><input class="merged" data-bind="value: mPrefix" readonly="readonly" /><span data-bind="text: '@' + domain"></span></span></li>
            </ul>
        </div>
    </div>
</div>

The JS

JS

function ViewModel(){
    var self = this;

    self.contacts = ko.observableArray([
        { firstName:'John', mPrefix: 'john.doe', domain: 'domain.com', lastName: 'Doe', department: 'Sales', phone: '+358 12 345 6789' },
        { firstName:'Joe', mPrefix: 'joe.w', domain: 'wonder.com', lastName: 'Wonder', department: 'Time wasting', phone: '+358 98 765 4321' },
        { firstName:'Mike', mPrefix: 'yo', domain: 'rappin.com', lastName: 'Rophone', department: 'Audio', phone: '+358 11 222 3333' }
    ]);
    self.msgMeToThis = ko.observable('');
    self.reveal = function(m, e){
        var name = e.target.attributes.href.value;
        name = name.replace('#', '');
        self.msgMeToThis(name);
    };
}
var viewModel = new ViewModel();
ko.applyBindings(viewModel);

回答by SimonDowdles

One of my favorite methods is to obfuscate the email address using php, a classic example is to convert the characters to HEX values like so:

我最喜欢的方法之一是使用 php 混淆电子邮件地址,一个经典的例子是将字符转换为 HEX 值,如下所示:

function myobfiscate($emailaddress){
 $email= $emailaddress;                
 $length = strlen($email);                         
 for ($i = 0; $i < $length; $i++){                
 $obfuscatedEmail .= "&#" . ord($email[$i]).";";
 }
 echo $obfuscatedEmail;
}

And then in my markup I'll simply call it as follows:

然后在我的标记中,我将简单地调用它如下:

  <a href="mailto:<?php echo myobfiscate('[email protected]'); ?>"
title="Email me!"><?php echo myobfiscate('[email protected]');?> </a>

Then examine your source, you'll be pleasantly surprised!

然后检查你的来源,你会惊喜!