<?php
English verification code is relatively simple, do not make hex processing, directly with the color value is OK. If
Session_Start ();
function Rand_create ()
{
Notifies the browser that a PNG image will be exported
Header ("Content-type:image/png");
Get the random number generator seed ready.
Srand (Double) microtime () *1000000);
Prepare the relevant parameters for the picture
$im = Imagecreate (62,22);
$black = Imagecolorallocate ($im, 0,0,0); RGB Black Identifier
$white = Imagecolorallocate ($im, 255,255,255); RGB White Identifier
$gray = Imagecolorallocate ($im, 200,200,200); RGB Gray Identifiers
Start drawing
Imagefill ($im, 0,0, $gray);
while (($randval =rand ()%100000) <10000); {
$_session["Auth_code"] = $randval;
Drawing a four-bit integer verification code into a picture
Imagestring ($im, 5, 3, $randval, $black);
}
adding interfering pixels
for ($i =0; $i <200; $i + +) {
$randcolor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $randcolor);
}
Output validation Picture
Imagepng ($im);
Destroy image identifiers
Imagedestroy ($im);
}
Rand_create ();
?>
The making of digital verification code