PHP Simple Build Verification Code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.