search
HomeBackend DevelopmentPHP TutorialRecommend a PHP verification code program_PHP tutorial

Recommend a PHP verification code program_PHP tutorial

Jul 13, 2016 pm 05:10 PM
phpone timesharerecommendhavefriendComparecodeprogramverify

Share a better PHP verification code program for reference by friends in need.

for($i=0;$i $num .= rand(0,9);
The code is as follows
 代码如下 复制代码

代码如下:
   /*   网站验证码程序
    *   运行环境: PHP5.0.18 下调试通过
    *   需要 gd2 图形库支持(PHP.INI中 php_gd2.dll开启)
    *   文件名: showimg.php
    *   作者:  17php.com
    *   Date:   2007.03
    */

   //随机生成一个4位数的数字验证码
    $num="";
    for($i=0;$i     $num .= rand(0,9);
    }
   //4位验证码也可以用rand(1000,9999)直接生成
   //将生成的验证码写入session,备验证页面使用
    Session_start();
    $_SESSION["Checknum"] = $num;
   //创建图片,定义颜色值
    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);

    //随机绘制两条虚线,起干扰作用
    $style = array($black, $black, $black, $black, $black, $gray, $gray, $gray, $gray, $gray);
    imagesetstyle($im, $style);
    $y1=rand(0,20);
    $y2=rand(0,20);
    $y3=rand(0,20);
    $y4=rand(0,20);
    imageline($im, 0, $y1, 60, $y3, IMG_COLOR_STYLED);
    imageline($im, 0, $y2, 60, $y4, IMG_COLOR_STYLED);

    //在画布上随机生成大量黑点,起干扰作用;
    for($i=0;$i     {
   imagesetpixel($im, rand(0,60), rand(0,20), $black);
    }
    //将四个数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
    $strx=rand(3,8);
    for($i=0;$i     $strpos=rand(1,6);
    imagestring($im,5,$strx,$strpos, substr($num,$i,1), $black);
    $strx+=rand(8,12);
    }
    ImagePNG($im);
    ImageDestroy($im);
   ?>

Copy code



The code is as follows:
/* Website verification code program
* * Running environment: Passed debugging under PHP5.0.18
* * Requires gd2 graphics library support (php_gd2.dll in PHP.INI is enabled) * File name: showimg.php
 代码如下 复制代码

Recommend a PHP verification code program_PHP tutorial
.....
* Author: 17php.com

* * Date: 2007.03
*/

//Randomly generate a 4-digit verification code
 代码如下 复制代码
$code=$_POST["passcode"];
if( $code == $_SESSION["Checknum"]){
验证通过
}else{
验证码错误
}
...
$num="";
} //4-digit verification code can also be generated directly using rand(1000,9999) //Write the generated verification code into the session for use on the verification page Session_start(); $_SESSION["Checknum"] = $num; //Create a picture and define the 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); //Draw two dotted lines randomly to interfere $style = array($black, $black, $black, $black, $black, $gray, $gray, $gray, $gray, $gray); imagesetstyle($im, $style); $y1=rand(0,20); $y2=rand(0,20); $y3=rand(0,20); $y4=rand(0,20); Imageline($im, 0, $y1, 60, $y3, IMG_COLOR_STYLED); Imageline($im, 0, $y2, 60, $y4, IMG_COLOR_STYLED); // Randomly generate a large number of black dots on the canvas to interfere; for($i=0;$i { imagesetpixel($im, rand(0,60), rand(0,20), $black); } //Display four numbers randomly on the canvas, and the horizontal spacing and position of the characters are randomly generated according to a certain fluctuation range $strx=rand(3,8); for($i=0;$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, you will see a graphical verification code, and a new code will be randomly generated every time it is refreshed. 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
Recommend a PHP verification code program_PHP tutorial ..... This will display the verification code image. When you get 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"]){ Verified }else{ Verification code error } ...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629690.htmlTechArticleShare a better php verification code program for reference by friends in need. The code is as follows Copy the code The code is as follows: ?php /* Website verification code program * Running environment: PHP5.0.18 Downgrade...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools