PHP Simple Verification Code (GD library)

Source: Internet
Author: User

Forum in order to prevent irrigation, there have been a lot of verification code plug-ins, now here is a very simple custom verification code function, this verification code implementation of the principle is through the PHP extension of the GD library to achieve.

Give the definition of the verification code of Baidu Encyclopedia " Verification Code (CAPTCHA) is" Completely automated public Turing test to tell Computers and humans Apart "(Fully automatic distinction computer and human Turing Test is a public automatic program that distinguishes whether a user is a computer or a person . Can prevent: Malicious crack password, brush tickets , forum irrigation, effectively prevent a hacker to a particular registered users with a specific program to brute force to break the way of the landing attempt, in fact, with the verification code is now a lot of web site way (such as China Merchants Bank online personal banking, Baidu community), We implemented this function in a relatively simple way. "

Through the above introduction, in fact, the verification code is a code, the code used to place the robot to brute force, can be some difficult to identify the image, it can be some interactive work, or some graphical calculation formula. The following is a simple PHP verification code:

<pre code_snippet_id= "454247" snippet_file_name= "blog_20140819_1_8343085" name= "code" class= "PHP" >image_code <span style= "font-family:arial, Helvetica, Sans-serif;" > (6);</span>
function Image_code ($length) {header (' content-type:image/png '); $rand = '; for ($i =0; $i < $length; $i + +) {$rand. = Dechex (rand (0,15));} $im = Imagecreatetruecolor (75,25), $blue = Imagecolorallocate ($im, 0,102,255), Imagefill ($im, 0,0, $blue); $white = Imagecolorallocate ($im, 255,255,255); Imageline ($im, 0,0,20,20, $white); Imageline ($im, 0,2,75,20, $white); Imagestring ($im, 5,0,0, "$rand", $white), Imagepng ($im); Imagedestroy ($im); }


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.