Verification code always error PHP code instance

Source: Internet
Author: User
If you want to use the PHP drawing function, first of all to enable the function of this module. Just remove the php_gd2.dll in front of the php.ini.
Start drawing below:

Copy the Code code as follows:


  Session_Start ();
Generate a Captcha picture
Header ("Content-type:image/png");
$im = Imagecreate (44,18); Draw a picture that specifies a wide 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-bit 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 interfering pixels
{
$randcolor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $randcolor); Image Point function
}
Imagepng ($im);
Imagedestroy ($im);
?>


Basically this is the way to achieve, in fact, if the picture to water printing is nothing more than to write in the picture, the principle is similar.
Use the place directly
Fill in the name of this PHP file and you can use it.

The above describes the verification code is always wrong PHP code instance codes, including the verification code is always the error content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.