Simple instance PHP verification code code

Source: Internet
Author: User

Verification code is a public fully automated program that distinguishes users from computers and people. In the CAPTCHA test, the computer that serves as the server automatically generates a problem to be answered by the user. This problem can be generated and judged by the computer, but it must be solved only by humans. Because the computer cannot answer the CAPTCHA problem, the user who answers the question can be considered human.

*/
Session_Start ();
$string = null;
$im = Imagecreatetruecolor (60,25); Create a true Color map 60*25
$BG = Imagecolorallocate ($im, 255,255,255);//white background
Imagefill ($im, 0,0, $BG); padding White
$x = 5;//
$y = 0;//text coordinates
for ($i =0; $i <4; $i + +)
{
$char = Mt_rand (0,9);
$string. = $char;
$y = Mt_rand (0,10);
$ccolor = Imagecolorallocate ($im, Mt_rand (0,230), Mt_rand (0,230), Mt_rand (0,230));
Imagechar ($im, 6, $x, $y, $char, $ccolor);/Fill Text
$x + + mt_rand (10,15);
}
for ($i =0; $i
{
$x 1 = mt_rand (0,80);
$x 2 = Mt_rand (0,80);
$y 1 = mt_rand (0,30);
$y 2 = Mt_rand (0,30);
$x 2 = $x 1 +mt_rand (1,5);
$y 2 = $y 1 +mt_rand (1,5);
$LC = Imagecolorallocate ($im, Mt_rand (0,230), Mt_rand (0,230), Mt_rand (0,230));
Imageline ($im, $x 1, $y 1, $x 2, $y 2, $LC);/Fill Line
}
$_session[' Code ' = MD5 ($string);
Header ("Content-type:image/jpeg");
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.