WarpConduit Computing

  • Quick Tips
  • Web Design & Development
  • Graphic Design
  • Home
  • WordPress Plugins
  • Password Generator
  • About
  • Contact

mailto: Email Link Obfuscation (Hiding)

April 1, 2010 by Josh Hartman

After searching for a good email link obfuscation script that allows the address to be seen as normal text i came upon a webpage that had a good solution, so i did a little reverse engineering and created this PHP script to output the same code, enjoy!

<?php
/**
 * @author Josh Hartman
 * @copyright 2010
 */
 
function strToHex($string, $prepend=null)
{
    $hex='';
    for ($i=0; $i < strlen($string); $i++)
    {
        $hex .= $prepend.dechex(ord($string[$i]));
    }
    return $hex;
}
 
function createRandomPassword() {
    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;
    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    return $pass;
}
 
function mailto_link($email){
    if(preg_match('/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,4}$/i',$email)){
        $var1 = createRandomPassword();
        $var2 = createRandomPassword();
        $email = explode('@',$email);
        $user = strToHex($email[0],'%');
        $domain_array = array_reverse(explode('.',$email[1]));
        $domain = "'";
        foreach ($domain_array as $k=>$v){
            $domain_array[$k] = strToHex($v,'%');
        }
        $domain = "'".implode("','",$domain_array);
        $domain .= "'";
        $output = $var1."=['".$user."',[".$domain."].reverse().join('.')].join('@');".$var2."=unescape(".$var1.");document.write(".$var2.".link('mai'+'lto:'+".$var1."));";
        $output = "<script type=\"text/javascript\">eval(unescape(\"".strToHex($output,'%')."\"));</script>";
        echo $output;
    }else{
        return false; //email address is not valid
    }
}
 
mailto_link('username@domain.com'); //use this function wherever you want an email link
?>

<?php /** * @author Josh Hartman * @copyright 2010 */ function strToHex($string, $prepend=null) { $hex=''; for ($i=0; $i < strlen($string); $i++) { $hex .= $prepend.dechex(ord($string[$i])); } return $hex; } function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } function mailto_link($email){ if(preg_match('/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,4}$/i',$email)){ $var1 = createRandomPassword(); $var2 = createRandomPassword(); $email = explode('@',$email); $user = strToHex($email[0],'%'); $domain_array = array_reverse(explode('.',$email[1])); $domain = "'"; foreach ($domain_array as $k=>$v){ $domain_array[$k] = strToHex($v,'%'); } $domain = "'".implode("','",$domain_array); $domain .= "'"; $output = $var1."=['".$user."',[".$domain."].reverse().join('.')].join('@');".$var2."=unescape(".$var1.");document.write(".$var2.".link('mai'+'lto:'+".$var1."));"; $output = "<script type=\"text/javascript\">eval(unescape(\"".strToHex($output,'%')."\"));</script>"; echo $output; }else{ return false; //email address is not valid } } mailto_link('username@domain.com'); //use this function wherever you want an email link ?>

Filed Under: Web Design & Development Tagged With: email, link, mailto, obfuscation, php

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • Extremely Useful Applications for Web Development and IT Tasks
  • Installing BookStack Wiki on cPanel Shared Hosting
  • Media (MIME) Type Reference List

Tags

automatic base64 benchmark cache counter css deflate email font gzip htaccess html image inarray increment inline images in_array javascript jquery link list magento mailto menu metadot mysql number obfuscation opencart operating system order php random redirect rewriterule slashes software timestamp ubuntu unix upgrade url windows windows 7 wordpress

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2021 WarpConduit Computing. All Rights Reserved.