Three PHP Chinese characters English Verification code generation program

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags array_rand code fish image learning net php programming

Three kinds of PHP tutorials Chinese characters English verification code generation program

$ChineseChar = Explode (', ', "People, out, come, friends, learn, filial piety, benevolence, righteousness, propriety, low, loyal, country, medium, easy, white, man, Fire, king, Gold, wood, thunder, Wind, dragon, Tiger, Day, Earth, life, halo, Vegetable, bird, field, three, hundred, money, blessing, love, feeling, beast, worm, fish, Nine, net, new, degree, eh, alas, Ah, oh, Miriam, old, Little, day, month, star, Ken, each, Cheng ");


$k [0]= $ChineseChar [Array_rand ($ChineseChar)];


$k [1]= $ChineseChar [Array_rand ($ChineseChar)];


$k [2]= $ChineseChar [Array_rand ($ChineseChar)];


$k [3]= $ChineseChar [Array_rand ($ChineseChar)];


$cookie _str=implode (", $k);


Setcookie (' vrify ', MD5 ($cookie _str), Time () +600);


$str [0]=iconv (' gb2312 ', ' UTF-8 ', $k [0]);


$str [1]=iconv (' gb2312 ', ' UTF-8 ', $k [1]);


$str [2]=iconv (' gb2312 ', ' UTF-8 ', $k [2]);


$str [3]=iconv (' gb2312 ', ' UTF-8 ', $k [3]);


//Constructed image


$x _size=100;


$y _size=25;


$font = ' Simhei.ttf ';


$pic =imagecreate ($x _size, $y _size);


$background _color = imagecolorallocate ($pic, 255, 255, 255);


$FOREGROUNDARR = Array (imagecolorallocate ($pic, rand (0), rand (0,), rand (0, 20)),


imagecolorallocate ($pic, rand (0), rand (0, ten), rand (245, 255)),


imagecolorallocate ($pic, rand (245, 255), rand (0), rand (0, 10)),


Imagecolorallocate ($pic, rand (245, 255), rand (0), rand (245, 255));


Imagettftext ($pic, Mt_rand (12,15), Mt_rand ( -8,8), 6,mt_rand (19,22), $foregroundArr [Rand (0,3)], $font, $str [0]);


Imagettftext ($pic, Mt_rand (15,17), Mt_rand ( -8,8), 26,20, $foregroundArr [rand (0,3)], $font, $str [1]);


Imagettftext ($pic, Mt_rand (12,15), Mt_rand ( -8,8), 46,20, $foregroundArr [rand (0,3)], $font, $str [2]);


Imagettftext ($pic, Mt_rand (15,17), Mt_rand ( -8,8), 66,mt_rand (19,22), $foregroundArr [Rand (0,3)], $font, $str [3]);


for ($i =0 $i <80; $i + +)


       {


$pointcol = Imagecolorallocate ($pic, Rand (0,255), Rand (0,255), Rand (0,255));


Imagesetpixel ($pic, rand (2, $x _size-2), rand (2, $y _size-2), $pointcol);


       }


$border = Imagecolorallocate ($pic, 133, 153, 193);


Imagerectangle ($pic, 0, 0, $x _size-1, $y _size-1, $border);


imagepng ($pic);


Imagedestroy ($pic);


?>


<?php


session_start ();


session_set_cookie_params (0, '/');


$ENABLEGD = 1;


$funcs = Array (' Imagecreatetruecolor ', ' imagecolorallocate ', ' Imagefill ', ' imageline ', ' Imagedestroy ', ' Imagecolorallocatealpha ', ' imageellips tutorial e ', ' imagepng ');


foreach ($funcs as $func)


{


if (!function_exists ($func))


       {


$ENABLEGD = 0;


break;


       }


}


if (!function_exists (' Ob_gzhandler ')) Ob_clean ();

if ($ENABLEGD)
{
      //create captcha
        $consts = ' cdfgkmnpqrstwxyz23456 ';
       $vowels = ' aek23456789 ';
       for ($x = 0; $x < 6; $x + +)
       {
              $const [$x] = substr ($consts, Mt_ Rand (0,strlen ($consts)-1), 1);
              $vow [$x] = substr ($vowels, Mt_ Rand (0,strlen ($vowels)-1), 1);
      }
       $radomstring = $const [0]. $vow [0]. $const [2]. $const [1]. $vow [1]. $const [3]. $ VOW[3]. $const [4];
       $_session[' checkcode ' = $string = substr ($radomstring, 0,4);//only Display 4 STR
      //set up image, the FirsT number is the width and the second is the height
       $imageX = strlen ($radomstring) *8 ;      //the image Width
       $imageY = 20;                                            //the Image Height

Related Article

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.