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