热搜:NVER 

PHP验证码效能的实现

2024-05-01 10:48:02
 PHP验证码效能的实现

PHP验证码功能的实现

/**
	 *产生验证码图片
	 */
	public function actionVerfiycode() {
		Header ( "Content-type: image/gif" );
		$border = 0; //是否要边框 1要:0不要
		$how = 4; //验证码位数
		$w = $how * 15; //图片宽度
		$h = 20; //图片高度
		$fontsize = 5; //字体大小
		$alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母
		$number = "0123456789"; //验证码内容2:数字
		$randcode = ""; //验证码字符串初始化
		srand ( ( double ) microtime () * 1000000 ); //初始化随机数种子
		$im = ImageCreate ( $w, $h ); //创建验证图片
		$bgcolor = ImageColorAllocate ( $im, 255, 255, 255 ); //设置背景颜色
		ImageFill ( $im, 0, 0, $bgcolor ); //填充背景色
		if ($border) {
			$black = ImageColorAllocate ( $im, 0, 0, 0 ); //设置边框颜色
			ImageRectangle ( $im, 0, 0, $w - 1, $h - 1, $black ); //绘制边框
		}
		for($i = 0; $i open();	
		Yii::app()->session->add('randcode',$randcode);
		/*绘图结束*/
		Imagegif ( $im );
		ImageDestroy ( $im );
		/*绘图结束*/
	
	}
	


引自:http://www.admin5.com/article/20080314/75984.shtml