php随机输出验证码

Posted 小美好。

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php随机输出验证码相关的知识,希望对你有一定的参考价值。

<?php
$img = imagecreatetruecolor(100, 40);
$black = imagecolorallocate($img, 0x00, 0x00, 0x00);
$green = imagecolorallocate($img, 0x00, 0xFF, 0x00);
$white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
imagefill($img,0,0,$white);
//生成随机的验证码
$code = ‘‘;
for($i = 0; $i < 4; $i++) {
    $code .= rand(0, 9);
}
imagestring($img, 5, 10, 10, $code, $black);
//加入噪点干扰
for($i=0;$i<50;$i++) {
  imagesetpixel($img, rand(0, 100) , rand(0, 100) , $black);
  imagesetpixel($img, rand(0, 100) , rand(0, 100) , $green);
}
//输出验证码
header("content-type: image/png");
imagepng($img);
imagedestroy($img);





















以上是关于php随机输出验证码的主要内容,如果未能解决你的问题,请参考以下文章

php随机类型验证码

代码实现PHP生成各种随机验证码

PHP实现随机生成验证码功能

随机输出验证码

php之验证码小程序

php 总结(13) 验证码实现原理