Recommend a PHP Verification code program _php Tutorial

Source: Internet
Author: User
Share a better PHP verification code program, a friend of the need to reference.
The code is as follows Copy Code

The code is as follows:
/* Website Verification Code Program
* Operating Environment: PHP5.0.18 under Commissioning
* Requires GD2 graphics library support (php.ini in Php_gd2.dll)
* File name: showimg.php
* Author: 17php.com
* date:2007.03
*/

Randomly generate a 4-digit number verification code
$num = "";
for ($i =0; $i <4; $i + +) {
$num. = rand (0,9);
}
4-bit verification code can also be generated directly with Rand (1000,9999)
Writes the generated verification code to the session and verifies that the page uses
Session_Start ();
$_session["Checknum"] = $num;
Create a picture, define a color value
Header ("Content-type:image/png");
Srand (Double) microtime () *1000000);
$im = Imagecreate (60,20);
$black = Imagecolorallocate ($im, 0,0,0);
$gray = Imagecolorallocate ($im, 200,200,200);
Imagefill ($im, 0,0, $gray);

Randomly draw two dashed lines, play a role in jamming
$style = Array ($black, $black, $black, $black, $black, $gray, $gray, $gray, $gray, $gray);
Imagesetstyle ($im, $style);
$y 1=rand (0,20);
$y 2=rand (0,20);
$y 3=rand (0,20);
$y 4=rand (0,20);
Imageline ($im, 0, $y 1, $y 3, img_color_styled);
Imageline ($im, 0, $y 2, $y 4, img_color_styled);

A large number of black dots are randomly generated on the canvas, which acts as interference;
for ($i =0; $i <80; $i + +)
{
Imagesetpixel ($im, Rand (0,60), Rand (0,20), $black);
}
Randomly displays four numbers on the canvas, and the horizontal spacing and position of the characters are randomly generated at a certain range of fluctuations
$strx =rand (3,8);
for ($i =0; $i <4; $i + +) {
$strpos =rand (1,6);
Imagestring ($im, 5, $strx, $strpos, substr ($num, $i, 1), $black);
$strx +=rand (8,12);
}
Imagepng ($im);
Imagedestroy ($im);
?>


How to use:
This program can be run directly, after running can see a graphics verification code, each refresh is randomly generated new code.
When using this program on a page, you can use the following code:
The code is as follows:
.....
Please enter the verification code:

The code is as follows Copy Code


.....

This displays the Captcha picture. To the verification page, use the following code:
The code is as follows:
...

The code is as follows Copy Code
$code =$_post["passcode"];
if ($code = = $_session["Checknum"]) {
Validation by
}else{
Verification Code Error
}
...

http://www.bkjia.com/PHPjc/629690.html www.bkjia.com true http://www.bkjia.com/PHPjc/629690.html techarticle share a better PHP verification code program, a friend of the need to reference. The code below copies the code as follows:? PHP/* Website CAPTCHA Program * Operating environment: PHP5.0.18 down ...

  • 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.