开发者

Good e-mail link protection methods

Can you guys post methods of e-mail link spam-protection (in php or javascript)?

Basically I want to put a "mailto" link on a web page, like

<a href="mailto:pony@fuu.com">E-mail me</a>

but I don't want the spam bots to pick it u开发者_Python百科p and then spam me with penis enlargement emails :)

So far, I found a javascript obfuscator here: http://www.jottings.com/obfuscator/ Not sure how effective it is though..


JavaScript Solution

With JavaScript you can do the following.

emailE = ('yourname@' + 'emailserver.com')
document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')

With this, Crawlers can no longer read your email from source code.

PHP solution

With php you can convert your email to unicode values

function converte($email) {
    $p = str_split(trim($email));
    $new_mail = '';
    foreach ($p as $val) {
        $new_mail .= '&#'.ord($val).';';
    }
    return $new_mail;
}

and on your page use the function like

<?php echo converte('my@email.com'); ?>

Source code output will be something like

&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;


Here is a related question and the accepted answer covers a few protection methods and how well they work.

Your best bet is to use CSS code-redirection like so (taken from that link):

<span style="unicode-bidi:bidi-override; direction: rtl;">
moc.elpmaxe@zyx
</span>


I wrote a PHP function that takes an email, breaks it up, then uses JavaScript to put it back together

<?php
function php_split_js_make_email($phpemail)
{
    $pieces = explode("@", $phpemail);

    echo '
        <script type="text/javascript">
            var a = "<a href=\'mailto:";
            var b = "' . $pieces[0] . '";
            var c = "' . $pieces[1] .'";
                var d = "\' class=\'email\'>";
                var e = "</a>";
                document.write(a+b+"@"+c+d+b+"@"+c+e);
            </script>
            <noscript>Please enable JavaScript to view emails</noscript>
        ';
    }
?>

Demo: http://djave.co.uk/php-js-email-protector/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜