PHP Implementation Verification Code

Source: Internet
Author: User

(1) What are the common verification codes?
Image type, voice type, video type, SMS type, etc.

(2) What are the benefits of using a verification code?

① to prevent malicious hacking of passwords
such as some hackers in order to obtain user information, through different means to the server to send data to verify the accuracy of guessing user information.
② prevent malicious brush tickets, forum irrigation
This long-term presence in the Forum irrigation phenomenon, such as paste, and constantly send posts. Now Baidu Bar has been for the user posted time to do a time limit, when a certain amount of time to post too much can not continue to post.
③ to prevent malicious requests
If a user submits a form information, the server resources are wasted and malicious attacks are caused by constantly requesting data from the background.
④ Fun
This is a personal point of view, when we submit a form, such as encountered some interesting verification code, can enhance the user's love of the site.
⑤ getting user information
This is the current site is not uncommon in the matter. If we register a site account, you need to pass the phone verification code to register successfully. After getting the user's phone number, the website will send some marketing information to the phone number master.

(3) Environment configuration

Only need to install the local PHP GD extension library can be used. How to view, create a PHP file in the file written <?php phpinfo ();? , access the file, if you see the GD Library has been installed, you can use.

No, self-installing, Baidu many tutorials.

"Four" image processing functions

(1) Get image information

①getimagesize (): Get information such as image size, type, etc.

Gets the image size and related information, returns an array successfully, fails to return false and produces an e_warning level error message

<? PHP $array getimagesize ("Images/flower_1.jpg"); Print_r ($array);? >

Browser display:

 array   ([ 0] = 350//pixel value of image width  [ 1] + 318//pixel value of image height  [ 2] = 2//Class of image Type, the number returned is 
//1 = gif,2 = jpg,3 = png,4 = swf,5 = psd,6 = bmp,7 = TIFF (Intel byte order), 8 = TIFF (Motorol A byte order),
//9 = jpc,10 = jp2,11 = jpx,12 = jb2,13 = swc,14 = iff,15 = wbmp,16 = XBM
[ 3] + width= "height=" 318 "//width and height strings, can be used directly for HTML <image> tags [bits] + = 8//number of bits per color of the image, binary format [Channe LS] = 3//image channel value, RGB image default is 3 [MIME] = Image/jpeg//The MIME information for the image, which is used to send the correct information in the HTTP Content-type header information, such as header ("content-type:image/ JPEG ");)

②imagesx (): Get image width

Gets the width of the image in pixels, and the return value is an integer type

③imagesy (): Get Image Height

Used to get the height, syntax and usage of the image with Imagesx ()

Imagesx () and Imagesy () parameters are image resources returned by functions such as Imagecreatetruecolor (), Imagecreatefromjpeg ()

<? PHP     $img = Imagecreatefromjpeg ('./upload/01.jpg ');     // echo "$img"; output resource ID #3    Echo $img ), "<br/>";     Echo $img  );? >

(2) Create an image

①imagecreate (): Create a blank image

If we want to process the image, like any other image processing software, we need to create a canvas. The Imagecreate () and Imagecreatetruecolor () functions are used to create a blank image.

The parameter x, Y, respectively, is the width and height of the image to create the pixel value, returning an image resource

<?PHPHeader("Content-type:image/png"); //Create an image    $im= Imagecreate (.) or die("Create Image resource Failed"); //Picture background color    $BG= Imagecolorallocate ($im, 255, 255, 255); //text color    $text _color= Imagecolorallocate ($im, 0, 0, 255); //Use the Magettftext () function to print a line of text horizontally, to output Chinese, etc., which require TTF font support.Imagestring ($im, 5, 0, 0, "Hello world!",$text _color); //output images in PNG formatImagepng ($im); //Destroying image ResourcesImagedestroy ($im);?>

This example outputs a line of text in an image format: Hello world!. The other functions used in the example are described later.

②imagecreatetruecolor (): Create a true color blank image

function is similar to imagecreate () to create a true-color image that supports richer colors.

Syntax: resource imagecreatetruecolor (int x, int y)

Note: This function cannot be used in GIF file format.

(3) Destroying images

Imagedestroy ()

After the image processing is complete, use the Imagedestroy () directive to destroy the image resource to free up memory, although the function is not required, but it is a good practice to use it.

Syntax: BOOL Imagedestroy (resource image), specifically using the visible above to create an image example.

PHP Implementation Verification Code

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.