本PHP程序作用是从数据库中读取出手机号码或其他数据并生成图片,起到干扰采集防采集的作用。(英文或数字,如果要支持中文的话需要额外添加字库)。本代码为原创代码。 以下是代码:
1 <?php //前面不要有空行 2 $id=$_GET[id]; 3 include("admin/config.php"); 4 $sql="select * from user where id=$id"; 5 $data=mysql_fetch_array(mysql_query($sql)); 6 $p=SBC_DBC($data[Phone],1); 7 function get_str($str,$strlen=16) { 8 $str=stripslashes($str); 9 for($i=0;$i<$strlen;$i++) 10 if(ord(substr($str,$i,1))>0xa0) $j++; 11 if($j%2!=0) $strlen++; 12 $tmp_str=substr($str,0,$strlen); 13 return $tmp_str; 14 } 15 if($p<>''){ 16 //生成5位的数字图片 17 Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示 18 19 //定义图片宽高 20 $nwidth=120; 21 $nheight=25; 22 $im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象 23 24 //图片色彩设置 25 $background_color=imagecolorallocate($im,255,255,255); //匹配颜色 26 $text_color=imagecolorallocate($im,23,14,91); 27 28 //绘制图片边框 29 imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色 30 imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形 31 32 //srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子 33 //$randval=rand(); 34 $randval=$p; //5位数 35 imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串 36 37 38 //加入干扰因素 39 //for($i=0;$i<478;$i++) 40 //{ 41 //$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); 42 //imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点 43 //} 44 //imagestring($im,3,5,5,"A Simple Text String",$text_color); 45 //imageinterlace($im,1); 46 imagepng($im); //建立png图型 47 imagedestroy($im); //结束图型 48 49 }else{ 50 echo "<font size=2>商家未输入电话号码</font>"; 51 } 52 53 ?>
|