Zend - The PHP Company




Email

Add Code


Crypted E-mail for blocing SPAM  

Type: code fragment
Added by: ankurpatel
Entered: 28/08/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 7009
cryptemail() function will print e-mail address such a way that only browser will understand it, and display the correct text corresponding to each character. This function is very useful to stop SPAM. It will make it hard for normal Web Spider/Crawler or any custom made e-mail harvesting script which gets all e-mail addresses for a web-page,dump in the database & do SPAM.


<?
################################################################################
#  Author: Ankur Patel                                                         #
#                                                                              #
#    Date: Does it really matter?                                              #
#                                                                              #
# Contact: ankurpateL78@yahoo.com                                              #
#                                                                              #
#    Note: cryptemail() function will print e-mail address such a way that     #
#          only browser will understand it, and display the correct text       #
#          corresponding to each character. This function is very useful       #
#          to stop SPAM. It will make it hard for normal Web Spider/Crawler    #
#          or any custom made e-mail harvesting script which gets all          #
#          e-mail addresses for a web-page,dump in the database & do SPAM.     #
#          To see the demo- just run this script, and you will understand it.  #
#                                                                              #
# License: Freeware                                                            #
#                                                                              #
################################################################################

$usermail "ankur@patel.com";

$test cryptemail($usermail);

print 
"<a href='mailto:$test'>$test</a>";

function 
cryptemail($myemail)
{

  
$i=0// initializing the counter to count each character

  
do

  {

  
$codechar =  substr($myemail,$i,1); // Read each character of the string

  
$code ord($codechar); // Convert each character to its corresponding ASCII value/number

       
if($code == "&#0"// If space/NULL is there, don't print anything ( After last character what will happen?)
          
{
            print 
"";

          }
               else
                    {

                    
$cryptmail $cryptmail."&#$code"// Make a new string with cryptic ASCII codes

                    
}
   
$i++;

  } while(
$codechar != ""); // End of do-while loop

return $cryptmail;

// end of function

?>


Usage Example


Just run the script, and it will show you the demo.


Rate This Script





Search



This Category All Categories