PHP Generate Verification Code

Source: Internet
Author: User

create_code.php

<?php

Session_Start ();

Generate a Captcha picture

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

Full Digital

$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g"; To display the characters, you can make additions and deletions

$list = Explode (",", $str);

$cmax = count ($list)-1;

$verifyCode = ";

for ($i =0; $i < 5; $i + +) {

$randnum = Mt_rand (0, $cmax);

$verifyCode. = $list [$randnum]; Take out the characters and combine them into the captcha characters we want.

}

$_session[' Code ' = $verifyCode; Put characters in session

$im = Imagecreate (58,28); Create a picture

$black = Imagecolorallocate ($im, 0,0,0); This bar and the following three are set for the color

$white = Imagecolorallocate ($im, 255,255,255);

$gray = Imagecolorallocate ($im, 200,200,200);

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

Imagefill ($im, 0,0, $white); Fill a picture with color

Draw a verification code into a picture

Imagestring ($im, 5, 8, $verifyCode, $black); Write the captcha to the picture

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

{

Imagesetpixel ($im, Rand () p, rand () 0, $black); Add dot-like interferon

Imagesetpixel ($im, Rand () p, rand () 0, $red);

Imagesetpixel ($im, Rand () p, rand () 0, $gray);

Imagearc ($im, Rand () p, rand () p, a, A, a, $black); Add an arc-like interferon

Imageline ($im, Rand () p, rand () p, rand () p, rand () p, $red); Add line-like interferon

}

Imagepng ($im);

Imagedestroy ($im);

?>


PHP Generate Verification Code

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.