PHP Generate Image Verification code

Source: Internet
Author: User

<?PHP/** * Generate verification code * @param int $type * @param int $length * @return string*/functionBuildrandomstring ($type=1,$length=4){    if($type= = 1) {        //The join () function is an alias for the implode () function, which is used to turn the array into a string, and the first parameter is the contents of the element placed between the groups of elements        $chars=Join( "",Range(0, 9 ) ); } ElseIf($type= = 2) {                             //The range () function creates an array of elements that contain the specified range//array_merge () function merges one or more arrays into an array        $chars=Join( "",Array_merge(Range("A", "Z"),Range("A", "Z" ) ) ); } ElseIf($type= = 3) {        $chars=Join( "",Array_merge(Range("A", "Z"),Range("A", "Z"),Range(0, 9 ) ) ); }    if($length>strlen($chars )) {        Exit("String length is not enough" ); }    $chars=Str_shuffle($chars);//the Str_shuffle () function randomly scrambles all characters in a string    return substr($chars, 0,$length);//the substr () function returns the string of the specified part}

PHP Generate Image 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.