最新消息: 新版网站上线了!!!

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-zh-yh-qh-ch-nh-dh'; 

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

shuffle($codeArray); 

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

public function CreateImg() 

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

$img = imagecreate(130,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 < 8; $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; 

 

// 调用 echo $_SESSION['check_pic'] ;

 

 

?>

 

转载请注明:谷谷点程序 » PHP 验证码类