PHP Basic code for verification Code

Source: Internet
Author: User

header (' content-type:image/png ');//create canvas and set color, recommend the following method//$im =imagecreate ($width, $height); $im = Imagecreatetruecolor (200,100) Or Die (' cannot Initialize GD image ');//Create Background color $bg=imagecolorallocate ($im, 255,255,255); $line =imagecolorallocatealpha ($im, Mt_rand (50,255), Mt_rand (50,255), Mt_rand (50,255), Mt_rand (20,60)), Imagefill ($im, 0,0, $BG); for ($i =0; $i <4;$    i++) {$fontSize =mt_rand (40,80);    $fontColor =imagecolorallocatealpha ($im, Rand (0,120), Rand (0,120), Rand (0,120), Rand (20,80));    $data = "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";    $fontContent =substr ($data, Rand (0,strlen ($DATA)), 1);    $captcha _code.= $fontContent;    $x = ($i *100/4) +rand (10,30);    $y =10*rand (2,6); Imagestring ($im, $fontSize, $x, $y, $fontContent, $fontColor);} Increase the interference point for ($i =0; $i <200; $i + +) {$pixel =imagecolorallocatealpha ($im, Mt_rand (50,255), Mt_rand (50,255), Mt_rand (    50,255), Mt_rand (20,60)); Imagesetpixel ($im, Mt_rand (0,200), Mt_rand (0,100), $pixel);}    Add interference line for ($i =0; $i <5; $i + +) {imagesetthickness ($im, Mt_rand (1,5));    $line =imagecolorallocatealpha ($im, Rand (0,120), Rand (0,120), Rand (0,120), Rand (40,80)); Imageline ($im, Mt_ranD (0,200), Mt_rand (0,100), Mt_rand (0,200), Mt_rand (0,100), $line);} Imagepng ($im);//Destroy the object to facilitate system resource recovery Imagedestroy ($IM);

This is the most basic PHP captcha code

PHP Basic code for 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.