PHP Brief Verification Code

Source: Internet
Author: User
PHP Simple Verification Code



Class Verifyimg {
Public $fontSize = 15; Define font Size
Public $length = 4; Defining string Lengths
Public $width = 70; Define picture width
Public $height = 30; Define picture Height
public $im = null; Create a picture that specifies a wide height
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 + +) {//loop random character generation string
$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); Generate Background color
$frameColor = Imagecolorallocate ($this->im, 0, 255, 0);
for ($i = 0; $i < $this->length; $i + +) {
$charY = ($this->height + 9)/2 + rand (-1, 1); Defining the y-coordinate of characters
$charX = $i * 15 + 8; Defining character X coordinates
$text _color = imagecolorallocate ($this->im, 255, 0, 0); Generate character Color
$text _color = imagecolorallocate ($this->im, Mt_rand (255), Mt_rand (50, 200));
$angle = rand (-20, 20); Create a character angle
Write characters
Imagettftext ($this->im, $this->fontsize, $angle, $charX, $charY, $text _color, $this->font, $strNum [$i]);
}
for ($i = 0; $i <= 5; $i + +) {//cycle draw background line
$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 <=; $i + +) {//cycle draw background points, create a pitting effect
$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); Draw Border
Ob_clean ();
Header (' content-type:image/png ');
Imagepng ($this->im);
Imagedestroy ($this->im);
}
}
$img = new Verifyimg ();
$img->build ();
?> (fblww-0103)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.