一聚教程网:一个值得你收藏的教程网站

热门教程

三种php汉字英文验证代码生成程序

时间:2022-06-24 18:34:29 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码
$ChineseChar = explode(',',"人,出,来,友,学,孝,仁,义,礼,廉,忠,国,中,易,白,者,火 ,王,金,木,雷,风,龙,虎,天,地, 生,晕,菜,鸟,田,三,百,钱,福 ,爱,情,兽,虫,鱼,九,网,新,度,哎,唉,啊,哦,仪,老,少,日, 月 ,星,肯,各,程");
$k[0]=$ChineseChar[array_rand($ChineseChar)];
$k[1]=$ChineseChar[array_rand($ChineseChar)];
$k[2]=$ChineseChar[array_rand($ChineseChar)];
$k[3]=$ChineseChar[array_rand($ChineseChar)];
$cookie_str=implode('', $k);
setcookie('vrify',md5($cookie_str),time()+600);
$str[0]=iconv('gb2312','UTF-8',$k[0]);
$str[1]=iconv('gb2312','UTF-8',$k[1]);
$str[2]=iconv('gb2312','UTF-8',$k[2]);
$str[3]=iconv('gb2312','UTF-8',$k[3]);
//构造图像
$x_size=100;
$y_size=25;
$font='simhei.ttf';
$pic=imagecreate($x_size,$y_size);
$background_color = imagecolorallocate ($pic, 255, 255, 255);
$foregroundArr = array(imagecolorallocate($pic, rand(0, 20), rand(0, 20), rand(0, 20)),
                                      imagecolorallocate($pic, rand(0, 20), rand(0, 10), rand(245, 255)),
                                      imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(0, 10)),
                                      imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(245, 255)));
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),6,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[0]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),26,20,$foregroundArr[rand(0,3)],$font,$str[1]);
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),46,20,$foregroundArr[rand(0,3)],$font,$str[2]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),66,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[3]);
for ($i=0;$i<80;$i++)
       {
       $pointcol = imagecolorallocate($pic, rand(0,255), rand(0,255), rand(0,255));
              imagesetpixel($pic,rand(2,$x_size-2),rand(2,$y_size-2),$pointcol);
       }
$border = imagecolorallocate($pic, 133, 153, 193);
imagerectangle($pic, 0, 0, $x_size - 1, $y_size - 1,$border);
imagepng($pic);
imagedestroy($pic);
?>

 

 

 

 代码如下 复制代码

session_start();
session_set_cookie_params(0,'/');
$enablegd = 1;
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imageline','imagedestroy','imagecolorallocatealpha','imageellips教程e','imagepng');
foreach($funcs as $func)
{
       if(!function_exists($func))
       {
              $enablegd = 0;
              break;
       }
}
if(!function_exists('ob_gzhandler')) ob_clean();

if($enablegd)
{
       //create captcha
       $consts = 'cdfgkmnpqrstwxyz23456';
       $vowels = 'aek23456789';
       for ($x = 0; $x < 6; $x++)
       {
              $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
              $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
       }
       $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
       $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
       //set up image, the first number is the width and the second is the height
       $imageX = strlen($radomstring)*8;       //the image width
       $imageY = 20;                                          //the image height
       $im = imagecreatetruecolor($imageX,$imageY);

       //creates two variables to store color
       $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
       $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
                                             imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
                                             imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
                                             imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
       $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
       $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
       $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80);

       //fill image with bgcolor
       imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
       //writes string

 

 

     

 

 代码如下 复制代码

  if(function_exists('imagettftext'))
       {
              imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)],'ALGER.TTF', $string[0]);
              imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], 'ARIALNI.TTF', $string[1]);
              imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)],'ALGER.TTF', $string[2]);
              imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)],'arial.ttf', $string[3]);
       }
       else
       {
              imagestring($im, 5, 3, floor(rand(0,5))-1, $string[0], $foregroundArr[rand(0,3)]);
              imagestring($im, 5, 16, floor(rand(0,5))-1, $string[1], $foregroundArr[rand(0,3)]);
              imagestring($im, 5, 23, floor(rand(0,5))-1, $string[2], $foregroundArr[rand(0,3)]);
              imagestring($im, 5, 33, floor(rand(0,5))-1, $string[3], $foregroundArr[rand(0,3)]);
       }
       //strikethrough

       $border = imagecolorallocate($im, 133, 153, 193);
       //imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
       imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

       $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
       for ($i=0;$i<80;$i++)
       {
              imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
       }
       //random shapes
       for ($x=0; $x<9;$x++)
       {
              if(mt_rand(0,$x)%2==0)
              {
                     imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
                     imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
              }
              else
              {
                     imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
                     imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
              }
       }
       //output to browser
    header("content-type:image/png ");
       imagepng($im);
       imagedestroy($im);
}
else
{
exit("不能建立!");}
?>

function verify($user_str){//从cookie中对比用户的输入
        if(md5($cookie_str)==$_COOKIE['vrify'])
                return 1;
        else
                return 0;
}
function c2ch($num){
  $ch_h = chr(substr($num,0,2)+160);
  $ch_l = chr(substr($num,2,2)+160);
  return $ch_h.$ch_l;
}
function num_rand(){
        mt_srand((double)microtime() * 1000000);
        $d= mt_rand(16,36);
        $n= mt_rand(1,19);
        return c2ch($d*100+$n);
}
$k[0]=num_rand();
$k[1]=num_rand();
$k[2]=num_rand();
$k[3]=num_rand();
$cookie_str=implode('', $k);
setcookie('vrify',md5($cookie_str),time()+600);
$str[0]=iconv('gb2312','UTF-8',$k[0]);
$str[1]=iconv('gb2312','UTF-8',$k[1]);
$str[2]=iconv('gb2312','UTF-8',$k[2]);
$str[3]=iconv('gb2312','UTF-8',$k[3]);
//构造图像
$x_size=100;
$y_size=25;
$font='simhei.ttf';
$pic=imagecreate($x_size,$y_size);
$background_color = imagecolorallocate ($pic, 255, 255, 255);

$foregroundArr = array(imagecolorallocate($pic, rand(0, 20), rand(0, 20), rand(0, 20)),
                                             imagecolorallocate($pic, rand(0, 20), rand(0, 10), rand(245, 255)),
                                             imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(0, 10)),
                                             imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(245, 255)));
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),6,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[0]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),26,20,$foregroundArr[rand(0,3)],$font,$str[1]);
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),46,20,$foregroundArr[rand(0,3)],$font,$str[2]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),66,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[3]);
for ($i=0;$i<80;$i++)
       {
       $pointcol = imagecolorallocate($pic, rand(0,255), rand(0,255), rand(0,255));
              imagesetpixel($pic,rand(2,$x_size-2),rand(2,$y_size-2),$pointcol);
       }
$border = imagecolorallocate($pic, 133, 153, 193);
imagerectangle($pic, 0, 0, $x_size - 1, $y_size - 1,$border);
imagepng($pic);
imagedestroy($pic);
?>
积分238 阅读权限30 在线时间55 小时 注册时间2005-6-7 最后登录2010-6-9 查看详细资料
 TOP
FLASH路上-实时互动的远程培训 | 用画笔实现你的“原画设计师”梦想!

shentian [楼主]
中级会员

 

 

网络采集汉字验证码
$ChineseChar = explode(',',"人,出,来,友,学,孝,仁,义,礼,廉,忠,国,中,易,白,者,火 ,王,金,木,雷,风,龙,虎,天,地, 生,晕,菜,鸟,田,三,百,钱,福 ,爱,情,兽,虫,鱼,九,网,新,度,哎,唉,啊,哦,仪,老,少,日, 月 ,星,肯,各,程");
$k[0]=$ChineseChar[array_rand($ChineseChar)];
$k[1]=$ChineseChar[array_rand($ChineseChar)];
$k[2]=$ChineseChar[array_rand($ChineseChar)];
$k[3]=$ChineseChar[array_rand($ChineseChar)];
$cookie_str=implode('', $k);
setcookie('vrify',md5($cookie_str),time()+600);
$str[0]=iconv('gb2312','UTF-8',$k[0]);
$str[1]=iconv('gb2312','UTF-8',$k[1]);
$str[2]=iconv('gb2312','UTF-8',$k[2]);
$str[3]=iconv('gb2312','UTF-8',$k[3]);
//构造图像
$x_size=100;
$y_size=25;
$font='simhei.ttf';
$pic=imagecreate($x_size,$y_size);
$background_color = imagecolorallocate ($pic, 255, 255, 255);
$foregroundArr = array(imagecolorallocate($pic, rand(0, 20), rand(0, 20), rand(0, 20)),
                                      imagecolorallocate($pic, rand(0, 20), rand(0, 10), rand(245, 255)),
                                      imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(0, 10)),
                                      imagecolorallocate($pic, rand(245, 255), rand(0, 20), rand(245, 255)));
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),6,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[0]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),26,20,$foregroundArr[rand(0,3)],$font,$str[1]);
imagettftext($pic,mt_rand(12,15),mt_rand(-8,8),46,20,$foregroundArr[rand(0,3)],$font,$str[2]);
imagettftext($pic,mt_rand(15,17),mt_rand(-8,8),66,mt_rand(19,22),$foregroundArr[rand(0,3)],$font,$str[3]);
for ($i=0;$i<80;$i++)
       {
       $pointcol = imagecolorallocate($pic, rand(0,255), rand(0,255), rand(0,255));
              imagesetpixel($pic,rand(2,$x_size-2),rand(2,$y_size-2),$pointcol);
       }
$border = imagecolorallocate($pic, 133, 153, 193);
imagerectangle($pic, 0, 0, $x_size - 1, $y_size - 1,$border);
imagepng($pic);
imagedestroy($pic);
?>

 

热门栏目