Home  >  Article  >  Backend Development  >  Use image processing technology to generate verification codes (Typical application tutorial of PHP graphics images 3)

Use image processing technology to generate verification codes (Typical application tutorial of PHP graphics images 3)

黄舟
黄舟Original
2017-04-24 17:25:011990browse

Using image processing technology to generate verification codes (Typical application tutorial of PHP graphics and images 3)

There are many ways to implement the verification code function, including digital verification codes , graphic verification code and text verification code, etc. In this section, a verification code generated using image processing technology is introduced.

In the previous article "How to use the GD2 function to add text to pictures (Typical application tutorial of PHP graphics images 2)", we introduced how to add text to pictures Introduction, then today we will continue to introduce to you how to use image technology to generate verification codes.

The following introduces the use of image processing technology to generate verification codes. The specific code is as follows:

The output result is:

Use image processing technology to generate verification codes (Typical application tutorial of PHP graphics images 3)

The above is the simplest An example of generating a verification code. Below we introduce an example that is important in daily development. The specific steps are as follows:

(1) Create a checks.php file, use the GD2 function to create a 4-digit verification code in the file, and save the generated verification code in the Session variable. The code is as follows:

In the above code, when outputting the verification code, the position, color and font of each character are obtained through random numbers, and various verifications can be generated in the browser Code can also prevent malicious users from attacking the website system.

(2) Create a user login form, and call the checks.php file, output the content of the image in the form page, submit the form information, and use if conditional statements to determine whether the entered verification code is correct. If the verification code filled in by the user is equal to the randomly generated verification code, it will prompt "User login successfully!", the code is as follows:

 alert('验证码不能为空');window.location.
href='index.php';";
    }
//如果用户输入验证码的值与随机生成的验证码的值相等,则弹出登录成功提示
    if($checks==$_SESSION[check_checks]){
        echo "";
    }else{            //否则弹出验证码不正确的提示信息
        echo "";
    }
}
?>

You can try it on your own computer, and I will not post the picture here. Okay, that’s all about using image processing technology to generate verification codes. Below we will introduce to you "Using GD2 function to draw geometric figures (PHP graphics and images typical application tutorial 4)"!

The above is the detailed content of Use image processing technology to generate verification codes (Typical application tutorial of PHP graphics images 3). 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