• 技术文章 >后端开发 >php教程

    php容易验证码

    2016-06-13 13:15:20原创444
    php简单验证码
    
    
    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 ) );
    			$angle = rand ( - 20, 20 ); //生成字符角度
    			//写入字符
    			imagettftext ( $this->im, $this->fontSize, $angle, $charX, $charY, $text_color, $this->font, $strNum [$i] );
    		}
    		for($i = 0; $i <= 5; $i ++) { //循环画背景线
    			$linecolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
    			$linex = mt_rand ( 1, $this->width - 1 );
    			$liney = mt_rand ( 1, $this->height - 1 );
    			imageline ( $this->im, $linex, $liney, $linex + mt_rand ( 0, 4 ) - 2, $liney + mt_rand ( 0, 4 ) - 2, $linecolor );
    		}
    		for($i = 0; $i <= 32; $i ++) { //循环画背景点,生成麻点效果
    			$pointcolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
    			imagesetpixel ( $this->im, mt_rand ( 1, $this->width - 1 ), mt_rand ( 1, $this->height - 1 ), $pointcolor );
    		}
    		imagerectangle ( $this->im, 0, 0, $this->width - 1, $this->height - 1, $frameColor ); //画边框
    		ob_clean ();
    		header ( 'Content-type:image/png' );
    		imagepng ( $this->im );
    		imagedestroy ( $this->im );
    	}
    }
    $img = new VerifyImg ();
    $img->Build ();
    ?>
    

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇: HTTP 500 - 内部服务器异常 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• 请教QQ互联的代码是如何写的? • 关于网下商城是用伪静态好?还是生成静态好 • 没有上载的分数了,vip次数也用完了啊 • PHP登录跳转,该怎么处理 • 注册信息添加到数据库,该怎么处理
    1/1

    PHP中文网