php简单验证码
<!-- 网站建设www.ucantech.com
*@copyright(c)2011
*@author:Ernest
*@time:2011
*@version:new
-->
<?php
class VerifyImg {
public $fontSize = 15; //定义字体大小
public $length = 4; //定义字符串长度
public $width = 70; //定义图片宽度
public $height = 30; //定义图片高度
public $im = null; //生成一张指定宽高的图片
public $font = 'C:/Windows/Fonts/Arial.TTF';
public $strNum = "";
public function Build() {
$strings = Array ('1', '2','3', '4', '5', '6', '7', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' );
// $strNum = "";
$count = count ( $strings );
for($i = 1; $i <= $this->length; $i ++) { //循环随机取字符生成字符串
$strNum .= $strings [rand ( 0, $count - 1 )];
}
session_start ();
$_SESSION ["verifycode"] = $strNum;
$this->im = imagecreate ( $this->width, $this->height );
$backgroundcolor = imagecolorallocate ( $this->im, 255, 255, 255 ); //生成背景色
$frameColor = imageColorAllocate ( $this->im, 0, 255, 0 );
for($i = 0; $i < $this->length; $i ++) {
$charY = ($this->height + 9) / 2 + rand ( - 1, 1 ); //定义字符Y坐标
$charX = $i * 15 + 8; //定义字符X坐标
// $text_color = imagecolorallocate($this->im, 255, 0, 0); //生成字符颜色
$text_color = imagecolorallocate ( $this->im, mt_rand ( 50, 255 ), mt_rand ( 50, 128 ), mt_rand ( 50, 200 ) );
&nb