PHP implementation of web-side verification code function of the method of the detailed

Source: Internet
Author: User
Tags php language
This article is mainly for you to introduce PHP production Web-side verification code effect, the use of SMS Verification Code and web Verification Code practice, has a certain reference value, interested in small partners can refer to

We in the actual development, will use the SMS Verification Code and web verification code, relative to the cost of the page verification code is low, the safety factor also can be, next we will do a web-side verification code, directly on the code:

First, the file directory structure:

|----------Phpyanzheng project folder

|----Fonttype folder to put font files, font files generally end with. TTF and. OTF

|----1.php inside PHP language code

|----index.html inside the page layout

1.php

<?php header (' content-type:image/jpeg ');//define the code as JPEG file to parse $width = 120;//defines the width of the image $height = 40;//defines the high $element of the image = Array (' Q ', ' W ', ' e ', ' r ', ' t ', ' y ', ' u ', ' i ', ' o ', ' P ', ' l ', ' K ', ' j ', ' H ', ' G ', ' f ', ' d ', ' s ', ' a ', ' Z ', ' x ', ' C ', ' V ', ' b ', ' n ', ' m ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' 0 ', ' Q ', ' W ', ' E ', ' R ', ' T ', ' Y ', ' U ', ' I ', ' O ', ' P ', ' A ', ' S ', ' D ', ' F ', ' G ', ' H ', ' J ', '  K ', ' L ', ' M ', ' N ', ' B ', ' V ', ' C ', ' X ', ' Z ');//define an array of display text $string = '; for ($i =0; $i <4; $i + +) {$string. = $element [Rand (0,count ($element)-1)];//randomly generates four text targets} $img = Imagecreatetruecolor ($ width, $height);//Set the validation area width height $colorBg = imagecolorallocate ($img, Rand (185,255), Rand (185,255), Rand (185,255));// Generates a random number of 200-255 $colorBorder = Imagecolorallocate ($img, Rand (50,100), Rand (50,100), Rand (50,100)),//Border color $colorDian = Imagecolorallocate ($img, Rand (0,100), Rand (0,100), Rand (0,100))///Background dot color $colorLine = imagecolorallocate ($img, Rand (  0,255), Rand (0,255), Rand (0,255));  $colorString = Imagecolorallocate ($img, Rand (20,80), Rand (20,80), Rand (20,80)); Imagefill ($img, 0, 0,$COLORBG)///Set position and background color imagerectangle ($img, 0,0, $width-1, $height-1, $colorBorder);//Draw a border for ($i =0; $i <200; $i + +) {  Loop out 200 disturbance points imagesetpixel ($img, rand (0, $width-1), rand (0, $height-1), $colorDian); } for ($i =0; $i <round (5); $i + +) {//loop out 5 interference lines Imageline ($img, rand (0, $width/2), rand (0, $height/2), rand ($width/2,$  width), rand ($height/2, $height), $colorLine);    }//imagestring ($img, 4, 0, 0, ' A5DG ', $colorString);  Imagettftext ($img, 25,rand (5), Rand (0,40), $colorString, ' Fonttype/princetownstd.otf ', $string); Image name font size tilt angle start position x axis start position y axis color font position display content imagejpeg ($IMG);//Output Image?>

Index.html

<! DOCTYPE html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.