Verification Code
<?PHP//implement a simple verification code//session_startSession_Start();//Canvas$image= Imagecreatetruecolor (100, 30);//Set Fill Color$bgcolor= Imagecolorallocate ($image, 255, 255, 255);//FillImagefill ($image, 0, 0,$bgcolor);//Random Data//session$captcha _code= ' '; for($i= 0;$i< 4;$i++) { $fontsize= 5; $fontcolor= Imagecolorallocate ($image,Mt_rand(0, 120),Mt_rand(0, 120),Mt_rand(0, 120)); $data= ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ';//Echo strlen ($data);//Echo substr ($data, 61,1); $font=substr($data,Mt_rand(0,strlen($data)-1), 1); $captcha _code.=$font; $width= ($i* 100)/4 +Mt_rand(5, 10); $height=Mt_rand(5, 10); //AddImagestring ($image,$fontsize,$width,$height,$font,$fontcolor);}//Save to session$_session[' authcode '] =$captcha _code;//interference//pixel points for($i= 0;$i< 200;$i++) { $pixcolor= Imagecolorallocate ($image,Mt_rand(20, 200),Mt_rand(20, 200),Mt_rand(20, 200)); Imagesetpixel ($image,Mt_rand(0, 99),Mt_rand(0, 29),$pixcolor);}//Line for($i= 0;$i< 4;$i++) { $linecolor= Imagecolorallocate ($image,Mt_rand(50, 220),Mt_rand(50, 220),Mt_rand(50, 220)); Imageline ($image,Mt_rand(0, 99),Mt_rand(0, 29),Mt_rand(0, 99),Mt_rand(0, 99),$linecolor);}//OutputHeader(' Content-type:image/png '); Imagepng ($image);//destroyedImagedestroy ($image);
Validating forms
<?PHPif(isset($_request[' Authcode '])) { Session_Start(); //Judging if(Strtolower($_request[' authcode '] = =Strtolower($_session[' Authcode ']))) { Echo' Congratulations on your typing right! ‘; } Else { Echo' Input failed! ‘; } Exit();}?> for= "Authcode" > Please enter the contents of the Picture: </label> <input type= "text" name= "Authcode" id= "Authcode"/> </p> <p><input type= "Submit" value= "Submit"/></p></form></body>PHP Letter and number verification code