PHP Verification Code Instance Code

Source: Internet
Author: User
Tags rand

<?php
Session_Start ();
Generate Captcha Picture
Header ("Content-type:image/png");
$im = Imagecreate (44,18); Draw a picture that specifies the width and height
$back = Imagecolorallocate ($im, 245,245,245); Define background color
Imagefill ($im, 0,0, $back); Fill the background color into the picture you just drew.
$vcodes = "";
Srand (Double) microtime () *1000000);
Generate 4-digit numbers
For ($i =0 $i <4; $i + +) {
$font = Imagecolorallocate ($im, Rand (100,255), Rand (0,100), Rand (100,255)); Generate Random Colors
$authnum =rand (1,9);
$vcodes. = $authnum;
Imagestring ($im, 5, $i *10, 1, $authnum, $font);
}
$_session[' vcode ' = $vcodes;
For ($i =0 $i <100; $i + +)//Add interference pixels
{
$randcolor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $randcolor); The function of the element point of portrait
}
Imagepng ($im);
Imagedestroy ($im);

?>

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.