分享一个生成图片验证码的php类

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了分享一个生成图片验证码的php类脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

验证码的用途不用多说了,下面就介绍一个PHP验证码类

<>PHP

session_start();

Header("Content-tyPE: image/gif");

class SecurityCode

{

PRivate $codes = '';

function __construct()

{

$code = '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';

$codeArray = explode('-',$code);

shuffle($codeArray);

$this->codes = implode('',array_slice($codeArray,4));

}

public function Createimg()

{

$_SESSION['check_pic'] = $this->codes;

$img = imagecreate(70,25);

imagecolorallocate($img,222,222);

$testcolor1 = imagecolorallocate($img,255,0);

$testcolor2 = imagecolorallocate($img,51,51);

$testcolor3 = imagecolorallocate($img,255);

$testcolor4 = imagecolorallocate($img,255);

for ($i = 0; $i < 4;="">

{

imagestring($img,rand(5,6),8 + $i * 15,rand(2,8),$this->codes[$i],rand(1,4));

}

imagegif($img);

}

}

$code = new SecurityCode();

$code->Createimg();

$code = NULL;

?>

封装成类之后,加入了构造函数,使用起来也方便些。你也可以继续完善下这个验证码类,比如加入析构函数,如何更节省内存等等

脚本宝典总结

以上是脚本宝典为你收集整理的分享一个生成图片验证码的php类全部内容,希望文章能够帮你解决分享一个生成图片验证码的php类所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: