您好,欢迎访问一九零五行业门户网

PHP生成图片验证码功能详解

这篇文章主要介绍了php生成图片验证码功能,结合实例形式简单介绍了php生成验证码图片的操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
具体如下:
只是简单的用随机函数实现了图片的生成,没有对验证的整个流程做介绍。
代码如下:
<?php /** * created by jetbrains phpstorm. * user: lee * to change this template use file | settings | file templates. */ header("content-type:image/png"); $validatelength=4; $strtodraw=""; $chars=[ "0","1","2","3","4", "5","6","7","8","9", "a","b","c","d","e","f","g", "h","i","j","k","l","m","n", "o","p","q","r","s","t", "u","v","w","x","y","z", "a","b","c","d","e","f","g", "h","i","j","k","l","m","n", "o","p","q","r","s","t", "u","v","w","x","y","z" ]; $imgw=80; $imgh=25; $imgres=imagecreate($imgw,$imgh); $imgcolor=imagecolorallocate($imgres,255,255,100); $color=imagecolorallocate($imgres,0,0,0); for($i=0;$i<$validatelength;$i++){ $rand=rand(1,58); $strtodraw=$strtodraw." ".$chars[$rand]; } imagestring($imgres,5,0,5,$strtodraw,$color); for($i=0;$i<100;$i++){ imagesetpixel($imgres,rand(0,$imgw),rand(0,$imgh),$color); } imagepng($imgres); imagedestroy($imgres);
运行效果如下:
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关推荐:
php实现网站验证码功能
php封装的验证码类详解
php实现封装的验证码类
以上就是php生成图片验证码功能详解的详细内容。
其它类似信息

推荐信息