Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Digital CAPTCHA with php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use php to achieve digital CAPTCHA, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

Php to achieve digital verification code methods: 1, through the imagecreatetruecolor function to achieve verification code base map; 2, through the imagecolorallocate method to achieve digital verification code; 3, to add interference elements; 4, to store verification information.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php implement digital CAPTCHA?

Implementation of Digital CAPTCHA with php

The verification code is realized by php. The verification code is to distinguish the operation of the machine from the human and improve the security. Need to install the server software, I use wamp, and then write the php CAPTCHA page.

It is divided into the following steps:

1. Realize the base map of CAPTCHA

Goal: to generate a 100*30px-sized picture through php code

Method: resource imagecreatetruecolor (int $width,int $height)

Note:

(a) rely on GD extension

(B) before exporting a picture, you must output the header information of the picture in advance.

(C) the default output of this method is black background.

/ /

Second, the realization of digital verification code

Method: int imagecolorallocate (resource $image,int $red,int $green,int $blue)

Bool imagestring (resource $image,int $font,int $x mint $yjinl string $sjimint $col)

Note: / control font size and distribution to avoid font overlap or incomplete display

/ /

Third, add interference elements

Goal: add interference elements, interference points or lines to the CAPTCHA

Method: bool imagesetpixel (resource $image,int $x minint $yjinint $color)

Bool imageline (resource $image,int $x1int $y1minint $x2minint $y2minint $color)

Note: interfering with the information must control the color to avoid "dominating the host"

Fourth, store verification information through SESSION

Goal: to record the CAPTCHA information on the server side so that the user can input it and verify it.

Method: bool session_start (void)

Note: (a) session_start () must be at the top of the script

(B) in the case of multiple servers, centralized management of session information needs to be considered.

The CAPTCHA is submitted and verified through the form

Goal: provide the generated verification code to the user and verify the correctness of the user verification code

Method: html form basis

Validate.php

Confirmation verification code

CAPTCHA picture:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report