PHP_ Making Verification Code

Source: Internet
Author: User

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

1<?PHP2     Header("Content-type:text/html;charset=utf-8");3     //set up 3 ranges of arrays4     $shuzi=Range(0,9);5     $zimuda=Range(' A ', ' Z ');6     $zimuxiao=Range(' A ', ' Z ');7 8     //Merge these 3 arrays into a new array9     $arr=Array_merge($shuzi,$zimuxiao,$zimuda);Ten  One     //traversing a new array A     foreach($arr  as $key=$value) { -         //if the element in the new array contains the following word, it is deleted (unset); -         if($value= = ' 0 ' | |$value= = ' 1 ' | |$value= = ' 2 ' | |$value= = ' O ' | |$value= = ' O ' the||$value= = ' I ' | |$value= = ' I ' | |$value= = ' Z ' | |$value= = ' Z ' | |$value= = ' L '){ -             //Delete the key, and the value is deleted -             unset($arr[$key]); -             } +         } -  +     //The array element is scrambled, its key value follows the element is disturbed A     Shuffle($arr); at     //4 Key values of the original array are randomly taken out -     $arr _rand=Array_rand($arr, 4); -     //Pass the key of the original array through the output, get 4 random verification code -     foreach($arr _rand  as $value) { -         Echo $arr[$value]; -     } in  -     //Optimization: 0,1,2 These 3 numbers originally need to exclude, just in the array of the first, continuous, in the definition of the range array can not write, directly from 3, reduce if judgment; uppercase and lowercase z can not be written at the end

PHP_ Making Verification Code

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.