Home>Article>Backend Development> How to implement php verification code

How to implement php verification code

(*-*)浩
(*-*)浩 Original
2019-09-16 11:54:31 6459browse

Verification code is the abbreviation of the fully automatic Turing test that distinguishes computers and humans. It is a public fully automatic program that distinguishes the user as a computer and a human.

How to implement php verification code

The main application scenarios of verification code: before logging in and registering, before posting and replying to information, and when a suspected machine request is made, human/machine verification is performed.

Implementation steps:

(1) Generate base map;

Depends on PHP image processing library GD

(2) Generate verification content;(Recommended learning:PHP programming from entry to proficiency)

To generate random numbers, use the PHP function rand();

(3) Generate verification code image;

(4) Verify verification content

Requires PHP to operate SESSION basics, Save the verification content on the server side; front-end Ajax basics

Code:

Create a new captcha.php file and write the following code. Implement the verification code picture:


      

View the effect as follows: refresh once, the content may change once

How to implement php verification code

Create a new form.php file and write the following code . Implementation verification:

 输出正确'; # code... }else{ echo $_REQUEST['authcode']; echo $_SESSION['authcode']; echo' 输出错误'; } exit(); } ?>     确认验证码 

验证码图片: " alt="" width="100" style="max-width:90%"> 换一个?

请输入图片中的内容:

The implementation results are as follows. Click to change one, and a verification code will be changed.

How to implement php verification code

#Enter the content in the picture. If it is correct, it will prompt you to enter it correctly. If it is wrong, it will prompt you to input it incorrectly. Modify the style yourself.

The above is the detailed content of How to implement php verification code. For more information, please follow other related articles on the PHP Chinese website!

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
Previous article:php array sorted by key Next article:php array sorted by key