澳门新葡萄京娱乐场phpwind验证码代码讲解

必要gd库援助.Image 图像函数参见 BY PHP 国度
关闭报错error_reporting(0State of Qatar;//图片宽度$x_size=60;//图片中度$y_size=20;//生成4个随机字符$nmsg=num_rand(4State of Qatar;//帮忙巴中通连接吗?$S=$_SERVER[‘SERVER_PORT’]==’443′
? 1:0;//使用cookie记录随机码//expire=0 cookie将会在对话甘休后失效。
setCookie(‘ck_num’,md5($nmsg),0,’/’,”,$S);//创建宽:60*20的图片(画布)$aimg
= imagecreate($x_size,$y_sizeState of Qatar;//设置图片背景观$back =
imagecolorallocate($aimg, 255, 255, 255State of Qatar;//设置字体颜色$border =
imagecolorallocate($aimg, 0, 0,
0State of Qatar;//从0,0点填充59*19的反革命矩形区域imagefilledrectangle($aimg, 0, 0,
$x_size – 1, $y_size – 1,
$back);//从0,0点绘制59*19的鲜红矩形边框imagerectangle($aimg, 0, 0,
$x_size – 1, $y_size – 1, $border卡塔尔;for ($i=0;$istrlen($nmsg卡塔尔国;$i++卡塔尔国{
//在图纸上写字 imageString($aimg,5,$i*$x_size/4+3,2,
$nmsg[$i],$border); }header(“Content-type:
image/png”);imagepng($aimg);imagedestroy($aimg);exit;function
num_rand($lenth卡塔尔国{ // 播下二个私下数爆发器种子
//php自4.2.0起,,此参数变为可选择,当该项为空时,会被设为随即数
mt_srand((double)microtime() * 1000000卡塔尔; //发生有4个随机数字的字符串
for($i=0;$i$lenth;$i++卡塔尔{ $randval.= mt_rand(0,9State of Qatar; }
//对含有4个数字的字符串使用md5加密,长度是叁11个人的
//从3长度为32的字符中,自最小数起或最大数32-$lenth起,取长度为$lenth的字符串
$randval=substr(md5($randval卡塔尔(قطر‎,mt_rand(0,32-$lenth),$lenth); return
$randval;}?

 代码如下

$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);
?>

 

 

 

 代码如下

<?php
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(“不能够创立!”卡塔尔国;}
?>

<?php
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 小时 注册时间二〇〇五-6-7 最终登陆二零零六-6-9
查看详细资料
 TOP
FLASH路上-实时相互的远程培养操练 | 用画笔达成您的“原画设计员”梦想!

shentian [楼主]
中档会员

 

 

互连网采访汉字验证码
<?php
$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);
?>

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注