您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php生成验证码图片程序_PHP教程

2024/3/28 5:48:25发布13次查看
一款国外网站下载的php生成验证码图片代码,这个比较实用我们还举例说明了,有需要的朋友按上面保存成php就可以用了哦。
 代码如下 复制代码
name:
email:
message:
security code:
验证程序 captchasecurityimages.php
 代码如下 复制代码
generatecode($characters);
  /* font size will be 75% of the image height */
  $font_size = $height * 0.75;
  $image = @imagecreate($width, $height) or die('cannot initialize new gd image stream');
  /* set the colours */
  $background_color = imagecolorallocate($image, 255, 255, 255);
  $text_color = imagecolorallocate($image, 20, 40, 100);
  $noise_color = imagecolorallocate($image, 100, 120, 180);
  /* generate random dots in background */
  for( $i=0; $i   imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  }
  /* generate random lines in background */
  for( $i=0; $i   imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
  }
  /* create textbox and add text */
  $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('error in imagettfbbox function');
  $x = ($width - $textbox[4])/2;
  $y = ($height - $textbox[5])/2;
  imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('error in imagettftext function');
  /* output captcha image to browser */
  header('content-type: image/jpeg');
  imagejpeg($image);
  imagedestroy($image);
  $_session['security_code'] = $code;
 }
}
$width = isset($_get['width']) ? $_get['width'] : '120';
$height = isset($_get['height']) ? $_get['height'] : '40';
$characters = isset($_get['characters']) && $_get['characters'] > 1 ? $_get['characters'] : '6';
$captcha = new captchasecurityimages($width,$height,$characters);
?>
http://www.bkjia.com/phpjc/629694.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/629694.htmltecharticle一款国外网站下载的php生成验证码图片代码,这个比较实用我们还举例说明了,有需要的朋友按上面保存成php就可以用了哦。 代码如下 复制...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product