PHP CAPTCHA Implementation Code Simple example _php tutorial

Source: Internet
Author: User
PHP Verification Code I have said a lot of examples, the following I turn a friend of the good PHP Verification Code program, quite simple friends can refer to.

Recently bored nothing to do, began to do some PHP sharing, the code is relatively simple, but more practical.

This is written four years ago, a few lines of code to implement the four-bit random number of PHP verification code function.

The code is as follows Copy Code

Session_Start ();
Header ("Content-type:image/jpeg");
$img = Imagecreate (50,20);
$white = Imagecolorallocate ($img, 211,213,193);
Imagefill ($img, 0,0, $white);

for ($i =0; $i <4; $i + +) {
$r [$i] = rand (0,9);
}
$_session[' valid ' = Implode ("", $r); Write to session here to do post-validation
for ($i =0; $i <4; $i + +) {

if (rand (0,9)%2==0) {
Imagechar ($img, 5, ($i + 1) *8,4, $r [$i],imagecolorallocate ($img, Rand (0,150), Rand (0,150), Rand (0,150)));
}else{
Imagechar ($img, 5, ($i + 1) *8,2, $r [$i],imagecolorallocate ($img, Rand (0,150), Rand (0,150), Rand (0,150)));
}

}
Imagejpeg ($IMG);

http://www.bkjia.com/PHPjc/629610.html www.bkjia.com true http://www.bkjia.com/PHPjc/629610.html techarticle PHP Verification Code I have said a lot of examples, the following I turn a friend of the good PHP Verification Code program, quite simple friends can refer to. Recently bored nothing to do, began to do some PHP ...

  • Related Article

    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.