简体   繁体   English

用PHP编码电子邮件,然后用JS解码

[英]Encode email with PHP then decode with JS

I'm working on a website that has many business profiles with their contact information which also include email addresses. 我正在一个拥有许多业务简介及其联系信息(包括电子邮件地址)的网站上工作。 Obviously I don't want to output the plain email addresses in the source due to spam. 显然,由于垃圾邮件,我不想在来源中输出纯电子邮件地址。 Could do mrsmith[at]gmail.com or obfuscate with ASCII but these solutions aren't ideal, not 100% foolproof. 可以做mrsmith [at] gmail.com或用ASCII混淆,但是这些解决方案不是理想的,不是100%可靠的。

The profiles do have a contact form but I also need to show the email addresses. 个人资料确实有联系表,但我还需要显示电子邮件地址。

What I want to do is encode the emails with PHP and then decode with JS and create the anchor link dynamically. 我想做的是用PHP编码电子邮件,然后用JS解码并动态创建锚链接。 So I need an algorithm that's the same in PHP an JS if there is any... 所以我需要一种与PHP和JS中相同的算法,如果有的话...

First, use SSL. 首先,使用SSL。 Then use an AJAX request to get the Data (jQuery will help with the AJAX). 然后使用AJAX请求获取数据(jQuery将帮助使用AJAX)。 Seperate it into two requests. 将其分为两个请求。 ex for yummyfood@mybusiness.com: 例如yummyfood@mybusiness.com:

One request that gives yummyfood. 一个请求给yummyfood。

Then have another request that gives mybusiness.com. 然后,再发送一个请求给mybusiness.com。

The last idea is to use recaptcha mailhide (by Google) . 最后一个想法是使用recaptcha mailhide(由Google提供) It will secure your email addressed just fine if that is the approach you want to take. 如果您要采用这种方法,它将确保您发送的电子邮件安全无虞。

I've now solved this with a form asking the user to fill in a value and submit it. 现在,我用一个表格来解决这个问题,该表格要求用户填写一个值并提交。 If value i correct, show email address. 如果值我正确,请显示电子邮件地址。 Also set an 'isHuman' session parameter so others emails will just show by default. 还要设置一个“ isHuman”会话参数,以便默认情况下仅显示其他电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM