...... Robots search the Web for input forms that allow them to insert ads, and nothing in the virtual world can stop them from misbehaving. These robots are extremely efficient and do not care about the original use of the form being attacked. Their only goal is to use their junk ads to cover your content, brutally seeking advertising revenue for their owners.
To verify that a form is facing a real person, this test is called CAPTCHA (fully automated public Turing test). The most effective method now is to generate a random pass phrase that requires user input, in order to prevent robotic cracking systems that support OCR (optical character recognition), the passphrase must be deformed, or partially blurred with random lines and dots.
/*generate a sequence of verification codes*/Define("Captcha_numchars", 6);//Verification Code Length$pass _phrase= "";//Verification Code Content for($i= 0;$i< Captcha_numchars;$i++) { //randomly generated letters added to verification code $pass _phrase.=CHR(Rand(97, 122));}/*generate a CAPTCHA image*/Define("Captcha_width", 300);//Verification Code WidthDefine("Captcha_height", 100);//Verify Code Height//create blank canvas$img= Imagecreatetruecolor (Captcha_width,captcha_height);//Set Theme Colors$BG _color= Imagecolorallocate ($img, 225, 225, 225);//White background$text _color= Imagecolorallocate ($img, 0, 0, 0);//Black Font$graphic _color= Imagecolorallocate ($img, 64, 64, 64);//Gray image//fill backgroundImagefilledrectangle ($img, 0, 0, captcha_width, Captcha_height,$BG _color);//draw a random line for($i= 0;$i< 10;$i++) {Imageline ($img, 0,Rand()% Captcha_height, Captcha_width,Rand()% Captcha_height,$graphic _color);}//Draw Random points for($i= 0;$i< 20;$i++) {Imagefilledellipse ($img,Rand()% Captcha_width,Rand()% Captcha_height, 10, 10,$graphic _color);}//Draw a verification codeImagettftext ($img, 0, Captcha_height-20,$text _color, "SketchFlow Print.ttf",$pass _phrase);//output as PNG imageHeader("Content-type:image/png"); Imagepng ($img);//undoing images from memoryImagedestroy ($img);
Dynamically generated images using PHP are not stored in a file, in fact, the imagepng () function generates a binary PNG image in the server's memory and then transfers it directly to the browser via a header.
This is why the PHP script can be placed directly in the SRC attribute of the tag:
PHP dynamically generated verification code