• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP图片验证码类_php

php 搞代码 7年前 (2018-06-19) 110次浏览 已收录 0个评论

php

class validateImage
{

var $x;
var $y;
var $numChars;
var $Code;

http://www.gaodaima.com/46910.htmlPHP图片验证码类_php

var $Width;
var $Height;
var $BG;
var $colTxt;
var $colBorder;
var $numCirculos;

//构造函数、初始值
function validateImage()
{
$this->x = $x;
$this->y = $y = “6”;
$this->numChars = $numChars = “4”; //Number of Code
$this->Code = $Code;
$this->Width = $Width = “80”; //Width of Image
$this->Height = $Height = “25”; //Height of Image
$this->BG = $BG = “255 255 255”; //RGB color of background
$this->colTxt = $colTxt = “0 0 0 0”; //RGB color of code
$this->Border = $colBorder = “100 100 100”; //RGB color of Border
$this->numCirculos = $numCirculos = “800”; //Number of random point
}

//Create base Image
function createImage()
{
//Create a image
$im = imagecreate ($this->Width, $this->Height) or die (“Cannot Initialize new GD image stream”);

//Get the RGB color code
$colorBG = explode(” “, $this->BG);

$colorBorder = explode(” “, $this->Border);

$colorTxt = explode(” “, $this->colTxt);

//put the background color on the image
$imBG = imagecolorallocate ($im, $colorBG[0], $colorBG[1], $colorBG[2]);

//put the border on the image
$Border = ImageColorAllocate($im, $colorBorder[0], $colorBorder[1], $colorBorder[2]);
$imBorder = ImageRectangle($im, 0, 0, $this->Width-1,$this->Height-1, $Border);

//put the code color on the image
$imTxt = imagecolorallocate ($im, $colorTxt[0], $colorTxt[1], $colorTxt[2]);

//Drop 800 points
for($i = 0; $i < $this->numCirculos; $i++)
{
$imPoints = imagesetpixel($im, mt_rand(0,80), mt_rand(0,80), $Border);
}

//put the Code on image
for($i = 0; $i < $this->numChars; $i++)
{
//get $x’s location
$this->x = 21 * $i + 5;

//get the code
mt_srand((double) microtime() * 1000000*getmypid());
$this->Code.= (mt_rand(0, 9));

$putCode = substr($this->Code, $i, “1”);

//put the code;
$Code = imagestring($im, 5, $this->x, $this->y, $putCode,$imTxt);

}

return $im;

}

//Transfer the code to next page
function transferCode()
{
//get the code
$this->createImage();
$vCode = $this->Code;

session_start();
session_register(vCode);

$_SESSION[‘validate_code’] = $vCode;

return $vCode;
}

//display the image
function show()
{
header(“Content-type:image/png”);
Imagepng($this->createImage());
Imagedestroy($this->createImage());
}

}
?>

欢迎大家阅读《PHP图片验证码类_php,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP图片验证码类_php

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址