PHP: Anti-Spam E-mail

I found these three anti-spam functions for e-mail in my WNLibrary-code, personally I like the second function the most.

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>
		';
}
	
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.'">[k0nsl anti-spam]</span>'.$script;

}

function antispambot($emailaddy, $mailto=0) {
	        $emailNOSPAMaddy = '';
	        srand ((float) microtime() * 1000000);
	        for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
	                $j = floor(rand(0, 1+$mailto));
	                if ($j==0) {
	                        $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';
	                } elseif ($j==1) {
	                        $emailNOSPAMaddy .= substr($emailaddy,$i,1);
	                } elseif ($j==2) {
	                        $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
	                }
	        }
	        $emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);
	        return $emailNOSPAMaddy;
}

Leave a Reply

Your email address will not be published. Required fields are marked *