PHP Write login Verification code function with call method, PHP verification Code _php Tutorial

Source: Internet
Author: User
Tags imagejpeg learn php learn php programming php write set cookie

PHP Write login Verification code function with call method, PHP verification code


The example of this article for everyone to share a PHP write login verification code function, for your reference, the specific content as follows

showkey.php

<?phpsession_start ();//Set Cookie or Sessionfunction Esetcookie ($name, $str, $life =0) {//This function will string str All lowercase strings make the captcha input case-insensitive----the same need to convert $_session[$name]=strtolower ($STR) in submitting a form for session comparison Get random characters This function is case-sensitive if case-insensitive can be added to the function strtolowerfunction Domake_password ($len) {$chars = array (/* "A", "B", "C", "D", "E "," F "," G "," H "," I "," J "," K "," L "," M "," N "," O "," P "," Q "," R "," s "," T "," U "," V "," w "," X "," Y "," Z "," A "," B "," C "," D "," E "," F "," G "," H "," I "," J "," K "," L "," M "," N "," O "," P "," Q "," R "," S "," T "," U "," V "," W "," X ",   "Y", "Z", */"0", "1", "2", "3", "4", "5", "6", "7", "8", "9");   $charsLen = count ($chars)-1;   Shuffle ($chars);//The array is scrambled $output = ""; for ($i =0; $i < $len; $i + +) {$output. = $chars [Mt_rand (0, $charsLen)];//Get an array element} return $output;} Show Captcha function ShowKey () {$key =domake_password (4);//Get random values $set =esetcookie ("Checkkey", $key);// Writes a random value to a cookie or session//whether the GD library if (function_exists ("imagejpeg")) {header ("CONTENT-TYPE:IMAGE/JPE") is supportedG ");  $img =imagecreate (47,20);  $blue =imagecolorallocate ($img, 102,102,102);  $white =imagecolorallocate ($img, 255,255,255);  $black =imagecolorallocate ($img, 71,71,71);  Imagefill ($img, 0,0, $blue);  Imagestring ($img, 5,6,3, $key, $white);  for ($i =0; $i <90; $i + +)//Add interfering pixel {imagesetpixel ($img, Rand ()%70,rand ()%30, $black);  } imagejpeg ($IMG); Imagedestroy ($IMG);  } elseif (Function_exists ("Imagepng")) {header ("content-type:image/png");  $img =imagecreate (47,20);  $blue =imagecolorallocate ($img, 102,102,102);  $white =imagecolorallocate ($img, 255,255,255);  $black =imagecolorallocate ($img, 71,71,71);  Imagefill ($img, 0,0, $blue);  Imagestring ($img, 5,6,3, $key, $white);  for ($i =0; $i <90; $i + +)//Add interfering pixel {imagesetpixel ($img, Rand ()%70,rand ()%30, $black);  } imagepng ($IMG); Imagedestroy ($IMG);  } elseif (Function_exists ("Imagegif")) {header ("content-type:image/gif");  $img =imagecreate (47,20);  $blue =imagecolorallocate ($img, 102,102,102);  $white =imagecolorallocate ($img, 255,255,255); $black =imageColorallocate ($img, 71,71,71);  Imagefill ($img, 0,0, $blue);  Imagestring ($img, 5,6,3, $key, $white);  for ($i =0; $i <90; $i + +)//Add interfering pixel {imagesetpixel ($img, Rand ()%70,rand ()%30, $black);  } imagegif ($IMG); Imagedestroy ($IMG);  } elseif (Function_exists ("Imagewbmp")) {header ("content-type:image/vnd.wap.wbmp");  $img =imagecreate (47,20);  $blue =imagecolorallocate ($img, 102,102,102);  $white =imagecolorallocate ($img, 255,255,255);  $black =imagecolorallocate ($img, 71,71,71);  Imagefill ($img, 0,0, $blue);  Imagestring ($img, 5,6,3, $key, $white);  for ($i =0; $i <90; $i + +)//Add interfering pixel {imagesetpixel ($img, Rand ()%70,rand ()%30, $black);  } imagewbmp ($IMG); Imagedestroy ($IMG);  } else {//does not support verification code header ("content-type:image/jpeg\r\n");  Header ("pragma:no-cache\r\n");  Header ("cache-control:no-cache\r\n");  Header ("expires:0\r\n");  $fp = fopen ("Data/vdcode.jpg", "R"); }}showkey ();? >

Call Method:

Copy the Code code as follows:

The above is the whole content of this article, I hope that you learn PHP programming help.

http://www.bkjia.com/PHPjc/1127835.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127835.html techarticle PHP Write Login verification code function with call method, PHP verification code This example for everyone to share a PHP write login verification code function, for your reference, the specific content as follows showkey.php ...

  • Related Article

    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.