Generation of "native" verification codes

Source: Internet
Author: User

<?PHP//set session, must be at the top of the scriptsession_start (); $image= Imagecreatetruecolor ( -, -);//1> function to set captcha picture size//set the captcha color imagecolorallocate (int im, int red, int green, int blue);$bgcolor = Imagecolorallocate ($image,255,255,255);//#ffffff//Zone fills an int imagefill (int im, int x, int y, int col) (x, y) where the area is shaded, and col represents the color to be paintedImagefill ($image,0,0, $bgcolor); //Setting Variables$captcha _code =""; //Generate random numbers   for($i =0; $i <4; $i + +){    //Set Font size$fontsize =6; //set Font color, random color$fontcolor = Imagecolorallocate ($image, Rand (0, -), Rand (0, -), Rand (0, -));//0-120 Dark Color//Set Number$fontcontent = rand (0,9); //Defining variables continuously$captcha _code. =$fontcontent; //Set coordinates$x = ($i * -/4) +rand (5,Ten); $y= rand (5,Ten);  Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor); }  //Save to session$_session['Authcode'] =$captcha _code; //add interference elements, set snowflake dots   for($i =0; $i < $; $i + +){    //set the color of the point, 50-200 color is lighter than the number, do not disturb reading$pointcolor = Imagecolorallocate ($image, Rand ( -, $), Rand ( -, $), Rand ( -, $)); //imagesetpixel-draw a single pixelImagesetpixel ($image, Rand (1, About), Rand (1, in), $pointcolor); }  //add interference elements, set horizontal lines   for($i =0; $i <4; $i + +){    //set the color of a line$linecolor = Imagecolorallocate ($image, Rand ( the, -), Rand ( the, -), Rand ( the, -)); //set line, 2.1-wireImageline ($image, Rand (1, About), Rand (1, in), Rand (1, About), Rand (1, in), $linecolor); }   //set the head, Image/pngHeader'Content-type:image/png'); //imagepng () Creating PNG graphics functionsimagepng ($image); //Imagedestroy () End graph function Destroy $imageImagedestroy ($image);

Form.php submitted Forms

<?PHP Header ("Content-type:text/html;charset=utf-8");//Set Header information//isset () detects if the variable is set  if(Isset ($_request['Authcode']) {session_start (); //strtolower () lowercase function    if(Strtolower ($_request['Authcode']) = = $_session['Authcode']){      //Jump PageEcho"<script language=\ "javascript\" >"; Echo"document.location=\ "./form.php\""; Echo"</script>"; }Else{      //tips and Jump pagesEcho"<script language=\ "javascript\" >"; Echo"alert (' Input error! ');"; Echo"document.location=\ "./zhuce.html\""; Echo"</script>";  } exit (); }

Generation of "native" verification codes

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.