PHP Generation Verification Code detailed tutorial _php tutorial

Source: Internet
Author: User
This article provides a PHP tutorial to generate a detailed tutorial of verification code, the first is about the build validation core code, followed by a build and Invoke method.

Header ("Content-type:image/png");
$num = ' 1234 ';
$imagewidth = 60;
$imageheight = 18;

$numimage = Imagecreate ($imagewidth, $imageheight);
Imagecolorallocate ($numimage, 240,240,240);
for ($i =0; $i
$x = Mt_rand (1,8) + $imagewidth * $i/4;
$y = Mt_rand (1, $imageheight/4);
$color =imagecolorallocate ($numimage, Mt_rand (0,150), Mt_rand (0,150), Mt_rand (0,150));
Imagestring ($numimage, 5, $x, $y, $num [$i], $color);
}

for ($i =0; $i <200; $i + +) {
$randcolor =imagecolorallocate ($numimage, Rand (200,255), Rand (200,255), Rand (200,255));
Imagesetpixel ($numimage, Rand ()%70,rand ()%20, $randcolor);
}
Imagepng ($numimage);
Imagedestroy ($numimage);
?>


Take a look at an example of generating a verification code

Generate a Captcha picture

Session_Start ();

Header ("Content-type:image/png");

Srand (Double) microtime () *1000000);

$roundnum =rand (1000,9999);

Put a random number in the session for later use

$_session["Sessionround"]= $roundnum;

$im = Imagecreate (58,28);

$red = Imagecolorallocate ($im, 255,0,0);

$blue = Imagecolorallocate ($im, 0,255,0);

Local area padding, equivalent to background

Imagefill ($im, 68,30, $red);

Drawing a four-bit integer verification code into a picture

Imagestring ($im, 5, 8, $roundnum, $blue);

for ($i =0; $i <50; $i + +)//Add interfering pixels

{

Imagesetpixel ($im, Rand ()%70, Rand ()%30, $black);

}

Imagepng ($im);

Imagedestroy ($im);

?>


HTML Call method

Verification Code

http://www.bkjia.com/PHPjc/633006.html www.bkjia.com true http://www.bkjia.com/PHPjc/633006.html techarticle This article provides a PHP tutorial to generate a detailed tutorial of verification code, the first is about the build validation core code, followed by a build and Invoke method. php//header (content-type:image ...

  • Related Article

    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.