加密邮箱地址,避免被爬虫抓取,发送垃圾信息

用简单的算法,对邮箱地址进行加密,解密:

<?php
function deCFEmail($encode){
    $k = hexdec(substr($encode,0,2));
    for($i=2, $m=''; $i < strlen($encode) - 1; $i += 2){
        $m.=chr(hexdec(substr($encode, $i, 2))^$k);
    }
    return $m;
}
function encodeEmail($email, $key=0) {
    $chars = str_split($email);
    $string = '';
    $key = $key ? $key : rand(10, 99);
    foreach ($chars as $value) {
        $string .= sprintf("%02s", dechex(ord($value)^$key));
    }
    return dechex($key).$string;
}

echo encodeEmail("abc@abc.com")."\n";
echo deCFEmail("4c2d2e2f0c2d2e2f622f2321")."\n";
?>

对应的js:

<script>
    !function () { "use strict"; function e(e) { try { if ("undefined" == typeof console) return; "error" in console ? console.error(e) : console.log(e) } catch (e) { } } function t(e) { return d.innerHTML = '<a href="' + e.replace(/"/g, "&quot;") + '"></a>', d.childNodes[0].getAttribute("href") || "" } function r(e, t) { var r = e.substr(t, 2); return parseInt(r, 16) } function n(n, c) { for (var o = "", a = r(n, c), i = c + 2; i < n.length; i += 2) { var l = r(n, i) ^ a; o += String.fromCharCode(l) } try { o = decodeURIComponent(escape(o)) } catch (u) { e(u) } return t(o) } function c(t) { for (var r = t.querySelectorAll("a"), c = 0; c < r.length; c++)try { var o = r[c], a = o.href.indexOf(l); a > -1 && (o.href = "mailto:" + n(o.href, a + l.length)) } catch (i) { e(i) } } function o(t) { for (var r = t.querySelectorAll(u), c = 0; c < r.length; c++)try { var o = r[c], a = o.parentNode, i = o.getAttribute(f); if (i) { var l = n(i, 0), d = document.createTextNode(l); a.replaceChild(d, o) } } catch (h) { e(h) } } function a(t) { for (var r = t.querySelectorAll("template"), n = 0; n < r.length; n++)try { i(r[n].content) } catch (c) { e(c) } } function i(t) { try { c(t), o(t), a(t) } catch (r) { e(r) } } var l = "/cdn-cgi/l/email-protection#", u = ".__cf_email__", f = "data-cfemail", d = document.createElement("div"); i(document), function () { var e = document.currentScript || document.scripts[document.scripts.length - 1]; e.parentNode.removeChild(e) }() }();
</script>

使用方式:

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c2d2e2f0c2d2e2f622f2321">[email&#160;protected]</a>

原文链接: https://www.cnblogs.com/xiaohunshi/p/12236262.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    加密邮箱地址,避免被爬虫抓取,发送垃圾信息

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/192436

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午6:02
下一篇 2023年2月12日 下午6:02

相关推荐