Php simply generates a verification code. Use the functions provided by php to generate image verification codes. For more information, see .? In the php Tutorial, muststartorcontinuesessionandsaveCAPTCHAstringin $ _ SE uses the functions provided by php to generate image verification codes. For more information, see.
// Must start or continue session and save CAPTCHA string in $ _ SESSION
// It to be available to other requests
If (! Isset ($ _ SESSION )){
Session_start ();
Header ('cache-control: private ');
}
// Create a 65*20 pixel image
$ Width = 65;
$ Height = 20;
$ Image = imagecreate (65,20 );
// Fill the image background color
$ Bg_color = imagecolorallocate ($ image, 0x33,0x66, 0xFF );
Imagefilledrectangle ($ image, 0, 0, $ width, $ height, $ bg_color );
// Fetch random text
$ Text = random_text (5 );
// Determine x and y coordinates for centering text
$ Font = 5;
$ X = imagesx ($ image)/2-strlen ($ text) * imagefontwidth ($ font)/2;
$ Y = imagesy ($ image)/2-imagefontheight ($ font)/2;
// Write text on image
$ Fg_color = imagecolorallocate ($ image, 0xFF, 0xFF, 0xFF );
Imagestring ($ image, $ font, $ x, $ y, $ text, $ fg_color );
// Save the CAPTCHA string for later comparison
$ _ SESSION ['captcha '] = $ text;
// Output the image
Header ('content-type: image/png ');
Imagepng ($ image );
Imagedestroy ($ image );
?>
Bytes. ? Php Tutorial // must start or continue session and save CAPTCHA string in $ _ SE...