PHP Production Verification Code

Source: Internet
Author: User

Purpose of Study:
Block machine requests to ensure that the business is not disturbed by machine submission requests.
Why to block:
In General Service-side business, write requests consume much more than read requests .
Technical points:
1. Implementation of the basemap and adding interference elements
2. Generate Validation Content
3. Verify that the content is stored on the server
4. Verifying the efficacy of the content

To implement a basemap:

Code:

<?php   $img  = Imagecreatetruecolor (100 , 30 ); //size   $bgColor  = imagecolorallocate ( $img , 0x00 , 0x00 , 0x00 ); Span class= "hljs-comment" >//background color  imagefill ( $img , 0 , 0 ,  $bgColor ); //Fill Color  header ( ' content-type:image/png ' ); Imagepng ( $img ); //destroy  Imagedestroy ( $img );   

Increase point interference and line interference:

<?php$img= Imagecreatetruecolor ( -, -);//Size$bgColor= Imagecolorallocate ($img,0xFF,0xFF,0xFF);//Background colorImagefill ($img,0,0,$bgColor);//Fill Color//Add random numbers for($i=0;$i<4;$i++){$numberSize=6;$numberColor= Imagecolorallocate ($img,Rand(0, -),Rand(0, -),Rand(0, -));//Dark zone    //Position not coincident    $x= ($i*100/4)+Rand(0,5);$y=Rand(5,Ten); Imagestring ($img,$numberSize,$x,$y,Rand(0,9),$numberColor);}//Increase point interference for($i=0;$i< $;$i++){//Interference color    $pointColor= Imagecolorallocate ($img,Rand( -, $),Rand( -, $),Rand( -, $)); Imagesetpixel ($img,Rand(0, -),Rand(0, -),$pointColor);}//Increase line interference for($i=0;$i<4;$i++){//Interference color    $lineColor= Imagecolorallocate ($img,Rand( the, $),Rand( the, $),Rand( the, $)); Imageline ($img,Rand(0, -),Rand(0, -),Rand(0, -),Rand(0, -),$lineColor);} Header' Content-type:image/png '); Imagepng ($img);//DestroyImagedestroy ($img);

Precautions:
Interference information must control the color, do not "distracting."

Verifying information through session storage

Goal:
Record verification code information on the server to facilitate user input
Method:
Session_Start ()
Precautions:
1.session_start** must be at the top of the script * *
2. Multi-server situation, need to consider centralized management session information

Solve the garbled problem yourself: Convert to UTF-8 no BOM format encoding.

The image and video verification principle is the same, just maintain a picture material library and its corresponding session relationship only.

implementation of Chinese verification Code :
Realize:
Imagettftext () method that relies on the GD library
Attention:
1.GBK encoding, you need to convert Chinese through iconv () to UTF-8
2. The selected TTF file needs to support Chinese

In Utf-8, does the Chinese font account for 3 bytes? (not sure).

PHP Production 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.