The use of PHP itself with the function to achieve the image verification code generation function, the need for friends can refer to.
Must start or continue session and save CAPTCHA string in $_session for
It to is 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);
?>
http://www.bkjia.com/PHPjc/629698.html www.bkjia.com true http://www.bkjia.com/PHPjc/629698.html techarticle using PHP's own function to implement the image verification code generation function, the need for friends can refer to. php Tutorial//must Start or Continue session and save CAPTCHA string in $_se ...