analyzer

请百分之百放心机器人不会来破解。

PHP代码
  1. /**  
  2.  * Encoded Mailto Link  
  3.  *  
  4.  * Create a spam-protected mailto link written in Javascript  
  5.  *  
  6.  * @access  public  
  7.  * @param   string  the email address  
  8.  * @param   string  the link title  
  9.  * @param   mixed   any attributes  
  10.  * @return  string  
  11.  */  
  12. if ( ! function_exists(\'safe_mailto\'))   
  13. {   
  14.     function safe_mailto($email$title = \'\'$attributes = \'\')   
  15.     {   
  16.         $title = (string) $title;   
  17.   
  18.         if ($title == "")   
  19.         {   
  20.             $title = $email;   
  21.         }   
  22.   
  23.         for ($i = 0; $i < 16; $i++)   
  24.         {   
  25.             $x[] = substr(\'<a href="mailto:\'$i, 1);   
  26.         }   
  27.   
  28.         for ($i = 0; $i < strlen($email); $i++)   
  29.         {   
  30.             $x[] = "|".ord(substr($email, $i, 1));  
  31.         }  
  32.  
  33.         $x[] = \'"\';   
  34.   
  35.         if ($attributes != \'\')   
  36.         {   
  37.             if (is_array($attributes))   
  38.             {   
  39.                 foreach ($attributes as $key => $val)   
  40.                 {   
  41.                     $x[] =  \' \'.$key.\'="\';   
  42.                     for ($i = 0; $i < strlen($val); $i++)   
  43.                     {   
  44.                         $x[] = "|".ord(substr($val, $i, 1));  
  45.                     }  
  46.                     $x[] = \'"\';   
  47.                 }   
  48.             }   
  49.             else  
  50.             {   
  51.                 for ($i = 0; $i < strlen($attributes); $i++)   
  52.                 {   
  53.                     $x[] = substr($attributes$i, 1);   
  54.                 }   
  55.             }   
  56.         }   
  57.   
  58.         $x[] = \'>\';   
  59.   
  60.         $temp = array();   
  61.         for ($i = 0; $i < strlen($title); $i++)   
  62.         {   
  63.             $ordinal = ord($title[$i]);   
  64.   
  65.             if ($ordinal < 128)   
  66.             {   
  67.                 $x[] = "|".$ordinal;   
  68.             }   
  69.             else  
  70.             {   
  71.                 if (count($temp) == 0)   
  72.                 {   
  73.                     $count = ($ordinal < 224) ? 2 : 3;   
  74.                 }   
  75.        
  76.                 $temp[] = $ordinal;   
  77.                 if (count($temp) == $count)   
  78.                 {   
  79.                     $number = ($count == 3) ? (($temp[\'0\'] % 16) * 4096) + (($temp[\'1\'] % 64) * 64) + ($temp[\'2\'] % 64) : (($temp[\'0\'] % 32) * 64) + ($temp[\'1\'] % 64);   
  80.                     $x[] = "|".$number;   
  81.                     $count = 1;   
  82.                     $temp = array();   
  83.                 }   
  84.             }   
  85.         }   
  86.   
  87.         $x[] = \'<\'$x[] = \'/\'$x[] = \'a\'$x[] = \'>\';   
  88.   
  89.         $x = array_reverse($x);   
  90.         ob_start();   
  91.   
  92.     ?><script type="text/javascript">   
  93.     //<![CDATA[   
  94.     var l=new Array();   
  95.     <?php   
  96.     $i = 0;   
  97.     foreach ($x as $val){ ?>l[<?php echo $i++; ?>]=\'<?php echo $val; ?>\';<?php } ?>   
  98.   
  99.     for (var i = l.length-1; i >= 0; i=i-1){   
  100.     if (l[i].substring(0, 1) == \'|\') document.write("&#"+unescape(l[i].substring(1))+";");   
  101.     else document.write(unescape(l[i]));}   
  102.     //]]>   
  103.     </script><?php   
  104.   
  105.         $buffer = ob_get_contents();   
  106.         ob_end_clean();   
  107.         return $buffer;   
  108.     }   
  109. }  

使用:

PHP代码
  1. <?php   
  2. echo safe_mailto(\'yourname@yourdomain.com\');  

会生成类似这样一段代码:

JavaScript代码
  1. <script type="text/javascript">   
  2.     //<![CDATA[   
  3.     var l=new Array();   
  4.     l[0]=\'>\';l[1]=\'a\';l[2]=\'/\';l[3]=\'<\';l[4]=\'|109\';l[5]=\'|111\';l[6]=\'|99\';l[7]=\'|46\';l[8]=\'|105\';l[9]=\'|119\';l[10]=\'|110\';l[11]=\'|111\';l[12]=\'|105\';l[13]=\'|115\';l[14]=\'|64\';l[15]=\'|101\';l[16]=\'|99\';l[17]=\'|105\';l[18]=\'|118\';l[19]=\'|114\';l[20]=\'|101\';l[21]=\'|115\';l[22]=\'>\';l[23]=\'"\';l[24]=\'|109\';l[25]=\'|111\';l[26]=\'|99\';l[27]=\'|46\';l[28]=\'|105\';l[29]=\'|119\';l[30]=\'|110\';l[31]=\'|111\';l[32]=\'|105\';l[33]=\'|115\';l[34]=\'|64\';l[35]=\'|101\';l[36]=\'|99\';l[37]=\'|105\';l[38]=\'|118\';l[39]=\'|114\';l[40]=\'|101\';l[41]=\'|115\';l[42]=\':\';l[43]=\'o\';l[44]=\'t\';l[45]=\'l\';l[46]=\'i\';l[47]=\'a\';l[48]=\'m\';l[49]=\'"\';l[50]=\'=\';l[51]=\'f\';l[52]=\'e\';l[53]=\'r\';l[54]=\'h\';l[55]=\' \';l[56]=\'a\';l[57]=\'<\';   
  5.     for (var i = l.length-1; i >= 0; i=i-1){   
  6.     if (l[i].substring(0, 1) == \'|\') document.write("&#"+unescape(l[i].substring(1))+";");   
  7.     else document.write(unescape(l[i]));}   
  8.     //]]>   
  9.     </script>  

显示效果如下:service@sionwi.com


分类:

技术点:

相关文章: