Posted By

fackz on 02/02/10


Tagged

email php hide


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

fackz
iroybot
BrianCoyDesign
sdpfost
joethermal


php hide email function


 / Published in: PHP
 

URL: http://www.maurits.vdschee.nl/php_hide_email/

PHP encrypts your E-mail address and generates the javascript that decrypts it. Most bots and spiders can't execute javascript and that is what makes this work.

  1. <?php
  2. function hide_email($email) { $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; $key = str_shuffle($character_set); $cipher_text = ''; $id = 'e'.rand(1,999999999); for ($i=0;$i<strlen($email);$i+=1) $cipher_text.= $key[strpos($character_set,$email[$i])]; $script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";'; $script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));'; $script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+d+"</a>"'; $script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")"; $script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>'; return '<span id="'.$id.'">[javascript protected email address]</span>'.$script; }
  3. ?>
  4.  
  5. //////////// USAGE ////////////
  6.  
  7. This is the PHP code you write where you want the E-mail address on your web page.
  8.  
  9. <?php echo hide_email('[email protected]'); ?>
  10.  
  11. This is what the E-mail address will look like for the visitor of your web page.
  12.  
  13. <span id="e401621484">[javascript protected email address]</span><script type="text/javascript">/*<![CDATA[*/eval("var a=\"[email protected]O6\";var b=a.split(\"\").sort().join(\"\");var c=\"p37p8p37pa1GC\";var d=\"\";for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));document.getElementById(\"e401621484\").innerHTML=\"<a href=\\\"mailto:\"+d+\"\\\">\"+d+\"</a>\"")/*]]>*/</script>

Report this snippet  

You need to login to post a comment.