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); }
: