How to make PHP verification code

Source: Internet
Author: User
Tags delete key
PHP makes a verification code, mainly using array-related functions

<?php    Header ("Content-type:text/html;charset=utf-8");    Set up 3 range array    $shuzi = range (0,9);    $zimuda = Range (' A ', ' Z ');    $zimuxiao = Range (' A ', ' Z ');    Merge these 3 arrays into a new array    $arr =array_merge ($shuzi, $zimuxiao, $zimuda);    Iterate through the new array    foreach ($arr as $key + $value) {        //If the element in the new array contains the following word, delete it (unset); if        ($value = = ' 0 ' | | $value = = ') 1 ' | | $value = = ' 2 ' | | $value = = ' o '  | | $value = = ' O '             | | $value = = ' I ' | | $value = = ' I ' | | $value = = ' Z ' | | $value = = ' Z ' | | $value = = ' L ') {            //delete key, the value is also deleted            unset ($arr [$key]);}        }    The array element is scrambled, and its key value follows the element is disturbed    shuffle ($arr);    The 4 key values of the original array are randomly taken    $arr _rand = Array_rand ($arr, 4);    The key of the original array is traversed output to get 4 random verification Code    foreach ($arr _rand as $value) {        echo $arr [$value];    }    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

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.