学而时习之

静坐当思己过,闲谈莫论人非

  IT博客 :: 首页 :: 联系 :: 聚合  :: 管理
  11 Posts :: 1 Stories :: 2 Comments :: 0 Trackbacks
本PHP程序作用是从数据库中读取出手机号码或其他数据并生成图片,起到干扰采集防采集的作用。(英文或数字,如果要支持中文的话需要额外添加字库)。本代码为原创代码。
以下是代码:
 1<?php //前面不要有空行 
 2$id=$_GET[id];
 3include("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);
 7function 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}
15if($p<>''){
16//生成5位的数字图片 
17Header("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//绘制图片边框 
29imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色 
30imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形 
31
32//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子 
33//$randval=rand(); 
34$randval=$p//5位数 
35imagestring($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); 
46imagepng($im); //建立png图型 
47imagedestroy($im); //结束图型 
48
49}else{
50echo "<font size=2>商家未输入电话号码</font>";
51}
52
53?>
posted on 2008-08-28 16:18 吟游诗人 阅读(667) 评论(3)  编辑 收藏 引用 所属分类: CD2SC.com网站开发相关PHP程序

Feedback

# re: [PHP]将数据库中的电话号码读取出来并生成图片 2009-01-24 18:55 howtocallchina
谢谢分享  回复  更多评论
  

只有注册用户登录后才能发表评论。