亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

一個(gè)PHP驗(yàn)證碼類代碼分享(已封裝成類)

 更新時(shí)間:2011年07月17日 13:05:02   作者:  
驗(yàn)證碼的用途就不用多說了,之前也寫了一篇關(guān)于PHP驗(yàn)證碼的文章,PHP 驗(yàn)證碼的實(shí)現(xiàn)。但是沒有封裝成類。下面就介紹一個(gè)PHP的一個(gè)驗(yàn)證碼類。
復(fù)制代碼 代碼如下:

<?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,0,4));
}
public function CreateImg()
{
$_SESSION['check_pic'] = $this->codes;
$img = imagecreate(70,25);
imagecolorallocate($img,222,222,222);
$testcolor1 = imagecolorallocate($img,255,0,0);
$testcolor2 = imagecolorallocate($img,51,51,51);
$testcolor3 = imagecolorallocate($img,0,0,255);
$testcolor4 = imagecolorallocate($img,255,0,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 SecurityCode();
$code->CreateImg();
$code = NULL;
?>

封裝成類之后,加入了構(gòu)造函數(shù),使用起來也方便些。你也可以繼續(xù)完善下這個(gè)驗(yàn)證碼類,比如加入析構(gòu)函數(shù),如何更節(jié)省內(nèi)存等等。

相關(guān)文章

最新評(píng)論