Verify code with PHP

Source: Internet
Author: User
Currently, many websites use verification codes to prevent users from actively registering, logging on, and injecting water using robots. The so-called verification code refers to a string of randomly generated numbers or symbols, a natural picture, the picture with some interference pixels (-

Currently, many websites use verification codes to prevent users from actively registering, logging on, and injecting water using robots. The so-called verification code refers to a string of randomly generated numbers or symbols, a natural picture, the picture with some interference pixels (to prevent OCR), the user can identify the verification code information with the naked eye, enter the form and submit the website for verification. after the verification is successful, you can apply a function.

?? Here we show you how to write a PHP program to implement the verification code:

?? Code 1:

   /*
* Filename: authpage. php
* Author: huuworm
* Date: 2004-09-26
* @ Copyleft huuworm.org
*/

Srand (double) microtime () * 1000000 );

// Verify whether the entered user is consistent with the verification code
If (isset ())
{
If (strcmp (,) = 0)
Echo 'verification successful! ';
Else
Echo 'verification failed! ';
}
  
// A new four-digit integer verification code
While (= rand () 000) <1000 );
?>
    

?? Code 2:

/*
* Filename: authimg. php
* Author: huuworm
* Date: 2003-04-28
* @ Copyleft huuworm.org
*/

// Native verification code Image
Header ('content-type: image/PNG ');
Srand (double) microtime () * 1000000 );
= Imagecreate (58,28 );
= ImageColorAllocate (, 0, 0 );
= ImageColorAllocate (, 255,255,255 );
= ImageColorAllocate (, 200,200,200 );
Imagefill (, 68, 30 ,);

// Print the four-digit integer verification code into the image
Imagestring (, 5, 10, 8 ,,);

For (= 0; <50;) // participates in the interference pixel
{
Imagesetpixel (, rand () p, rand () 0 ,);
}

ImagePNG ();
ImageDestroy ();
???>

?? This program runs in Apache 2.0.45 PHP 4.3.1.

The above is only a brief implementation of the verification code function, and the commercial security Title is not considered. To enhance security and put this effect into commercial use, you can follow these steps:

1. enable Session.
2. authnum is born in authimg. php, and md5sum is calculated and stored in session.

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.