PHP login verification code function attached call method, php verification code _ PHP Tutorial

Source: Internet
Author: User
Tags imagejpeg learn php programming set cookie
PHP login verification code function with call method, php verification code. The PHP login verification code function is provided with a call method. The php verification code example in this article shares a PHP login verification code function for your reference. The details are as follows: ShowKey. php PHP login verification code function attached call method, php verification code

This article provides an example of a PHP login verification code function for your reference. The details are as follows:

ShowKey. php

<? Phpsession_start (); // Set COOKIE or Sessionfunction esetcookie ($ name, $ str, $ life = 0) {// This function reduces all str strings and writes the string so that the verification code input is case-insensitive-the same function conversion is required for session comparison in the submission form $ _ SESSION [$ name] = strtolower ($ str );} // obtain random characters. This function is case sensitive. if it is case insensitive, add the 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); // disrupt the array $ output = ""; for ($ I = 0; $ I <$ len; $ I ++) {$ output. = $ chars [mt_rand (0, $ charsLen)]; // Get an array element} return $ output;} // display the verification code function ShowKey () {$ key = domake_password (4); // Get the random value $ set = esetcookie ("checkkey", $ key ); // write random values into cookies or sessions // whether the gd library if (function_exists ("imagejpeg") {header ("Content-type: image/jpeg") is supported "); $ img = imagecreate (102,102,102); $ blue = imagecolorallocate ($ img, 255,255,255); $ white = ImageColorAllocate ($ img,); $ black = ImageColorAllocate ($ img, 71); imagefill ($ img, 0, 0, $ blue); imagestring ($ img, 5, 6, 3, $ key, $ white); for ($ I = 0; $ I <90; $ I ++) // add interference pixels {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); imagefill ($ img, $ blue ); imagestring ($ img, 5, 6, 3, $ key, $ white); for ($ I = 0; $ I <90; $ I ++) // add interference pixels {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 interference pixels {imagesetpixel ($ img, rand () % 70, rand () % 30, $ black);} imagegif ($ img); imagedestroy ($ img);} elseif (function_exists ("imagewbmp") {header ("Content-type: image/vnd. wap. wbmp "); $ img = imagecreate (102,102,102); $ blue = imagecolorallocate ($ img, 255,255,255); $ white = ImageColorAllocate ($ img ); $ black = ImageColorAllocate ($ img, 71); imagefill ($ img, $ blue); imagestring ($ Img, 5, 6, 3, $ key, $ white); for ($ I = 0; $ I <90; $ I ++) // add interference pixels {imagesetpixel ($ img, rand () % 70, rand () % 30, $ black);} imagewbmp ($ img ); imagedestroy ($ img);} else {// 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:

The code is as follows:

The above is all the content of this article. I hope it will help you learn php programming.

Refer to the attached call method. The php verification code example in this article shares a login verification code function written in PHP for your reference. The details are as follows: ShowKey. php...

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.