php实现的一个email加密类,很好用,适合新手朋友参考。
代码:
<?php
/**
// Email加密类
// CLASS NAME: EMAILCRYPT
// FILE NAME : CLASS_EMAILCRYPT.INC.PHP
// EMAIL : j|u|l|i|e|n| [@] |p|a|c|h|e|t.c|o|m
*/
class emailcrypt {
var $crypted_text;
/*
* javascript 加密
*/
function _js_crypt ($text) { // 用javascript动态加密文本
//$html." "; // for a bug??
$html =chunk_split( bin2hex($text ),2,'%');
$html ='%'.substr($html,0,strlen($html)-1);
$html=chunk_split($html,54,"'+'");
$html= substr($html,0,strlen($html)-6);
$res= "<script type="text/javascript" language="JavaScript">n";
$res.="t<!--ntt document.write(unescape('$html'));nt //-->n";
$res.="</script>n";
return $res;
}
/*
* 加密email地址
* @param email: email地址
* @param text: the text or picture or anithing else to display
* @param crypt: 是否加密email地址
*/
function emailcrypt($email,$text,$crypt=true) {
$temp="<a href='mailto:$email'>$text</a>";
$this->crypted_text=($crypt)?$this->_js_crypt($temp):$temp;
}
/*
* get: 返回加密后的电子邮件地址
*/
function get() {
return $this->crypted_text;
}
}
?>
调用示例:
<?
require_once("class_emailcrypt.inc.php");
$m=new emailcrypt("toto@jb200.com","click to email toto");
echo $m->get();
?>