这篇文章主要为大家展示了“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如何实现生成图片验证码功能”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。