PHP _ production verification code, php production verification code

Source: Internet
Author: User

PHP _ production verification code, php production verification code

PHP creates a verification code, mainly using array-related functions

1 <? Php 2 header ("content-type: text/html; charset = UTF-8"); 3 // create an array of 3 ranges 4 $ shuzi = range ); 5 $ zimuda = range ('A', 'z'); 6 $ zimuxiao = range ('A', 'z '); 7 8 // combine the three numbers and form a new array 9 $ arr = array_merge ($ shuzi, $ zimuxiao, $ zimuda ); 10 11 // traverse the new array 12 foreach ($ arr as $ key => $ value) {13 // if the elements in the new array contain the following words, then delete it (unset ); 14 if ($ value = '0' | $ value = '1' | $ value = '2' | $ value = 'O' | $ value = 'O' 15 | $ value = 'I' | $ value = 'Z' | $ value = 'Z' | $ value = 'l ') {16 // Delete the key and the value will also delete 17 unset ($ arr [$ key]); 18} 19} 20 21 // disrupt the array element, the KEY-value-following element is disrupted by 22 shuffle ($ arr); 23 // randomly retrieve the four key values of the original array 24 $ arr_rand = array_rand ($ arr, 4 ); 25 // print the key of the original array and obtain four random verification codes 26 foreach ($ arr_rand as $ value) {27 echo $ arr [$ value]; 28} 29 30 // optimization: The numbers 0, 1, and 2 originally need to be excluded, just in the beginning of the array, continuous, when defining the range array can not be written, reduce the if judgment directly from 3. The uppercase/lowercase letter Z can also be left empty at the end.

 

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.