一个PHP验证码类代码分享(已封装成类)
分类:PHP作者:编程之家
<div class="codetitle"><a style="CURSOR: pointer" data="39619" class="copybut" id="copybut39619" onclick="doCopy('code39619')"> 代码如下:
<div class="codebody" id="code39619">
<?
PHP session_start();
Header("Content-type: image/gif");
class S
ecurityCode
{
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; $i++)
{
imagestring($img,rand(5,6),8 + $i * 15,rand(2,8),$this->codes[$i],rand(1,4));
}
imagegif($img);
}
}
$code = new S
ecurityCode();
$code->CreateImg();
$code = NULL;
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。