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);