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

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

<?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:

使用方式:

[email protected]

posted @ 2020-01-27 16:21  小魂师  阅读(1130)  评论(0)    收藏  举报