Seattle Web Design Seattle Web Design

Protect html email by PHP

 

If you need to have your email address on your php page, you need to protect it. Here is an option you have: 

1- Create an include php file like "email-hide.php" and saved it in your include folder.
2- Copy the following php code in it and save your file. 

<?php 
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- On your website header, include your hide-email.php file 

<!–Hiding email address PHP function–> 
<?php include "include\hide-email.php";  ?>

4- Go to the page you like to embed your email address and caste this piece of code.
<?php echo hide_email('name@domain.com'); ?>

* Do not forget to change "name@domain.com" to your desire email address.

 

Yee-Haw

 

 

 

 

 





Leave a Reply

 
Kianoush Facebook Profile Kianoush Google Plus Profile Kianoush LinkedIn Profile Find Kianoush Twitter