E-Mail-Adressen in einer Homepage schützen

  • Es ist ja immer schon mal ein Dauerthema, wie man denn seine E-Mail-Adresse so schützen kann, dass die SPAM-Bots diese nicht aus dem Quelltext der Seite auslesen können. Für diese und andere Gelegenheiten sollte dieses kleine Skript hilfreich sein, das Sie nur hier herauskopieren und unter z.B. str2unicode.php abspeichern müssen:

    <?php function hideMail(<#$>mail, <#$>text = '') { if(<#$>text == '') { <#$>text = <#$>mail; } <#$>mail = hide(<#$>mail); <#$>text = hide(<#$>text); return('<a href="mailto:' . <#$>mail . '">' . <#$>text . '</a>');}function hide(<#$>text) { return(utf8ToUnicodeEntities(utf8_encode(<#$>text)));}function utf8ToUnicodeEntities(<#$>source) { <#$>decrement[4] = 240; <#$>decrement[3] = 224; <#$>decrement[2] = 192; <#$>decrement[1] = 0; <#$>shift[1][0] = 0;<#$>shift[2][0] = 6; <#$>shift[2][1] = 0; <#$>shift[3][0] = 12; <#$>shift[3][1] = 6; <#$>shift[3][2] = 0; <#$>shift[4][0] = 18; <#$>shift[4][1] = 12; <#$>shift[4][2] = 6;<#$>shift[4][3] = 0; <#$>pos = 0; <#$>len = strlen(<#$>source); <#$>encodedString = ''; while(<#$>pos < <#$>len) { <#$>asciiPos = ord(substr(<#$>source, <#$>pos, 1)); if((<#$>asciiPos >= 240) && (<#$>asciiPos <= 255)) { <#$>thisLetter = substr(<#$>source, <#$>pos, 4); <#$>pos += 4; } else if((<#$>asciiPos >= 224) && (<#$>asciiPos <= 239)) { <#$>thisLetter = substr (<#$>source, <#$>pos, 3); <#$>pos += 3; } else if((<#$>asciiPos >= 192) && (<#$>asciiPos <= 223)) { <#$>thisLetter = substr (<#$>source, <#$>pos, 2); <#$>pos += 2; } else { <#$>thisLetter = substr (<#$>source, <#$>pos, 1); <#$>pos += 1; } <#$>thisLen = strlen(<#$>thisLetter);<#$>thisPos = 0; <#$>decimalCode = 0; while(<#$>thisPos < <#$>thisLen) { <#$>thisCharOrd = ord(substr(<#$>thisLetter, <#$>thisPos, 1)); if(<#$>thisPos == 0) {<#$>charNum = intval (<#$>thisCharOrd - <#$>decrement[<#$>thisLen]); <#$>decimalCode += (<#$>charNum << <#$>shift[<#$>thisLen][<#$>thisPos]); } else {<#$>charNum = intval (<#$>thisCharOrd - 128); <#$>decimalCode += (<#$>charNum << <#$>shift[<#$>thisLen][<#$>thisPos]); } <#$>thisPos++; } if(<#$>thisLen == 1) { <#$>encodedLetter = "&#". str_pad(<#$>decimalCode, 3, "0", STR_PAD_LEFT) . ';'; } else { <#$>encodedLetter = "&#". str_pad(<#$>decimalCode, 5, "0", STR_PAD_LEFT) . ';'; } <#$>encodedString .= <#$>encodedLetter; } return(<#$>encodedString);}?>


    Beispiel: Angenommen, dass Sie den Code unter dem Namen str2unicode.php abgespeichert haben, dann sieht das in der Praxis folgendermaßen aus: <?php include('str2unicode.php');?> <html><head><title>Geschützte E-Mail-Adresse</title></head><body><hr><p>Code: hide('irgend ein Text');</p><?php echo(hide('irgend ein Text')); ?><hr><p>Code: hideMail('addy@mail.de', 'text');</p><?php echo(hideMail('addy@mail.de', 'text')); ?><hr></body></html> Skript modifiziert von Stephan Hix