PHP verification code implementation code simple example _ PHP Tutorial

Source: Internet
Author: User
Simple example of PHP verification code implementation code. I have talked about a lot of PHP verification code examples. next I will turn to a friend's good PHP verification code program, which is quite simple for your reference. I have talked a lot about the php verification code for some PHP examples. next I will turn to a friend's PHP verification code program, which is quite simple for your reference.

Recently I am bored and have nothing to do. I started to share some php code, which is simple but practical.

This was written four years ago. several lines of code implement the php verification code function with four random numbers.

The code is as follows:

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 it here for post-verification.
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 );

Bytes. I 've been bored recently, so I started to do some php...

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.