php简单验证码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php简单验证码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2381字,纯文字阅读大概需要4分钟。
内容图文
![php简单验证码](/upload/InfoBanner/zyjiaocheng/150/4615abae88b94eb5a7f5d1b56f4bf155.jpg)
*@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 ) );
$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简单验证码全部内容,希望文章能够帮你解决php简单验证码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。