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.