Da das Thema heiss diskutiert wird, stelle ich hier mal die Methode von Typo3 vor, um Emailadressen zu verschlüsseln, meines Erachtens eine hervorragende Methode.
PHP-Code:
/**
* Encryption of email addresses for <A>-tags See the spam protection setup in TS 'config.'
*
* @param string Input string to en/decode: "mailto:blabla@bla.com"
* @param boolean If set, the process is reversed, effectively decoding, not encoding.
* @param string key for encrypt, either 'ascii' or int between -5 and 5
* @return string encoded/decoded version of $string
*/
function encryptEmail($string,$back=0,$method=1) {
$out = '';
if ($method === 'ascii') {
for ($a=0; $a<strlen($string); $a++) {
$out .= '&#'.ord(substr($string, $a, 1)).';';
}
} else {
for ($a=0; $a<strlen($string); $a++) {
$charValue = ord(substr($string,$a,1));
$charValue+= intval($method)*($back?-1:1);
$out.= chr($charValue);
}
}
return $out;
}
Der Link wird erzeugt mit
PHP-Code:
$link="javascript:linkTo_UnCryptMailto('".encryptEmail($mailToUrl)."');";
Dem HTML werden 2 JS-Routinen hinzugefügt:
Code:
// JS function for uncrypting spam-protected emails:
function UnCryptMailto(s) { //
var n=0;
var r="";
for(var i=0; i < s.length; i++) {
n=s.charCodeAt(i);
if (n>=8364) {n = 128;}
r += String.fromCharCode(n-(1));
}
return r;
}
// JS function for uncrypting spam-protected emails:
function linkTo_UnCryptMailto(s) { //
location.href=UnCryptMailto(s);
}
das Ergebnis sieht dann im Browser so aus: javascript
:linkTo_UnCryptMailto('nbjmup;tufggfoAejtmbct/ef');
Der Linktext wird z.B. so dargestellt:
empfänger<span>@</span>domain<span>.</span>de
wobei man das @ durch beliebige Zeichen ersetzen kann,z.B.(at), ebenso den Punkt, z.B. (dot)
wenn das nicht sicher ist ...