12306 captcha Code for PHP math operation verification Codes

Source: Internet
Author: User
Copy CodeThe code is as follows:


//-------------------------------------
File Description: Mathematical Operation Verification Code
File Author: Jesse Lee
Last update: 2008-09-07
//-------------------------------------
Session_Start ();
$sessionvar = ' Vdcode '; Session variable Name
$width = 150; Image width
$height = 20; Image Height
$operator = ' +-* '; Operator
$code = Array ();
$code [] = Mt_rand (1,9);
$code [] = $operator {Mt_rand (0,2)};
$code [] = Mt_rand (1,9);
$code [] = $operator {Mt_rand (0,2)};
$code [] = Mt_rand (1,9);
$codestr = Implode (' ', $code);
Eval ("\ $result =". Implode (", $code)."; ");
$code [] = ' = ';
$_session[$sessionvar] = $result;
$img = Imagecreate ($width, $height);
Imagecolorallocate ($img, Mt_rand (230,250), Mt_rand (230,250), Mt_rand (230,250));
$color = imagecolorallocate ($img, 0, 0, 0);
$offset = 0;
foreach ($code as $char) {
$offset + = 20;
$txtcolor = Imagecolorallocate ($img, Mt_rand (0,255), Mt_rand (0,150), Mt_rand (0,255));
Imagechar ($img, Mt_rand (3,5), $offset, Mt_rand (1,5), $char, $txtcolor);
}
for ($i =0; $i <100; $i + +) {
$pxcolor = Imagecolorallocate ($img, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255));
Imagesetpixel ($img, Mt_rand (0, $width), Mt_rand (0, $height), $pxcolor);
}
Header (' content-type:image/png ');
Imagepng ($IMG);
?>

The above describes the 12306 Verification code PHP Math Verification Code implementation codes, including the 12306 verification code aspects, I hope that the PHP tutorial interested friends helpful.

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