Implement the verification code function with PHP

zhaozj2021-02-08  196

Implement the verification code function with PHP

By Hutuworm

At present, many websites use the verification code technology to prevent users from using robots from automatically registering, logging in, and irrigation. The so-called verification code is to generate a random number or symbol, generate a picture, plus some interfering pixels (prevent OCR), by the user's naked eye identifies the verification code information, input form submission website verification, verification success You can use a feature.

  We show how to write a PHP program to implement the verification code function:

Code 1:

SRAND (Double) microtime () * 1000000);

/ / Verify that the user input is consistent with the verification code IF (isset ($ http_post_vars ['authinput')) {IF ($ http_post_vars ['Authnum'], $ http_post_vars ['Authinput']) == 0) ECHO " Verification is successful! "; Else Echo" Verification Failed! ";} // Generate new four-bit integer verification code while (($ authnum = rand ()% 10000) <1000);?>

Please enter the verification code:
> >

Code 2:

// Generate a verification code picture header ("content-type: image / png"); SRAND (Double) microtime () * 1000000); $ imagecreate (58, 28); $ black = imagecolorallocate ($ IM, 0 0,0); $ white = imagecoloralloccate ($ IM, 255, 255, 255); $ Gray = ImageColoralLocate ($ IM, 200, 200, 200); ImageFill ($ IM, 68, 30, $ GRAY); // Picking four integer verification入 Images, Images, $ IM, 5, 10, 8, $ HTTP_GET_VARS ['Authnum'], $ Black);

For ($ I = 0; $ I <50; $ I ) // Add Interference Pixel {ImageTpixel ($ IM, RAND ()% 70, Rand ()% 30, $ Black;

ImagePNG ($ IM); ImageDestroy ($ IM);

This article runs in the Apache 2.0.45 PHP 4.3.1 environment.

※ Pair of the temple: Free Software Document Infectious Source http://www.hutuworm.org

转载请注明原文地址:https://www.9cbs.com/read-3119.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.040, SQL: 9