The implementation of PHP verification code

Source: Internet
Author: User

?PHP/** * Make Verification code * *. Start the session*2. Set the header. Create a canvas. Create a color. Create a random number and place it on the canvas *6. Add a number of random numbers to the session *7. Adds a disturbance point or interference line *8. Output canvas *9. Destroying Canvas Resources *///1. Start SessionSession_Start();//2. Set the header to specify the MIME output typeHeader(' Content-type:image/png ');//3. Create a canvas$width= 100;$height= 30;$im= Imagecreate ($width,$height);//4. Create Colors$bgcolor= Imagecolorallocate ($im, 255,255,255);$textcolor= Imagecolorallocate ($im, 0,255,255);$randcolor= Imagecolorallocate ($im,Mt_rand(0,200),Mt_rand(0,200),Mt_rand(0,200));//5. Create a random number and place it on the canvas$verify=NULL; for($i= 0;$i<4;$i++){$temp=Mt_rand(0,9);$verify.=$temp; Imagestring ($im, 5,$i*15+15,8,$temp, Imagecolorallocate ($im,Mt_rand(0,200),Mt_rand(0,200),Mt_rand(0,200)));}//6 Put the generated random number in session$_session[' verify '] =$verify;//7. Adding interference points for($i= 0;$i<100;$i++) {Imagesetpixel ($im,Rand(0,$width),Rand(0,$height), Imagecolorallocate ($im,Rand(100,255),Rand(100,255),Rand(100,255)));}//8. Export the imageImagepng ($im);//imagegif ()//9. Destroying an imageImagedestroy ($im);?>

The implementation of PHP 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.