PHP Broken Code--CI Verification Code

Source: Internet
Author: User


When you write your own verification code, you are not allowed to position the text.


So the CI verification code the main part buckle out, see, general, interference line is the highlight


Code eliminates a lot of judgments, simplifies a lot, shows the same effect

<?php$defaults = array (     ' word '          =>  ',     ' Img_path '     =>  './',      ' Img_url '     =>  ',     ' img_width '      =>  ',     ' img_height '     =>  ' 30 ',      ' Font_path '     =>  '/instance/font/elephant.ttf ',      ' expiration '     => 7200,     ' word_length '     => 4,     ' Font_size '     => 16,      ' img_id '     =>  ',     ' pool '          =>  ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ',     ' CoLors '     => array (         ' background ')     => array (255,255,255),         ' border '     => array (153,102,102),         ' text '         => array (204,153,153),          ' Grid '         => array (255,182,182)      );//  the variable out of the array foreach  ($defaults  as  $key  =>  $val) {         $ $key  =  $val;}   Generate random code $word =  '; $pool _length = strlen ($pool); $rand _max =  $pool _length  - 1;for  ($i  = 0;  $i  <  $word _length;  $i +) {      $word  .=  $pool [Mt_rand (0,  $rand _max)];}   Verification CodeLength $length    = strlen ($word);//Angle $angle    =  ($length   &GT;=&NBSP;6)  ? mt_rand (-($length-6),  ($length-6))  : 0; $x _axis     = mt_rand (6,  (360/$length) -16); $y _axis =  ($angle  >= 0)  ? mt_ Rand ($img _height,  $img _width)  : mt_rand (6,  $img _height);//  Create a picture handle $im =  Imagecreatetruecolor ($img _width,  $img _height);//  Create color foreach  ($colors  as  $key  = >  $values) {     $colors [$key] = imagecolorallocate ($im,  $colors [$key ][0],  $colors [$key][1],  $colors [$key][2]);}   painted a large rectangle like the picture, which is the background imagefilledrectangle ($im, 0, 0,  $img _width,  $img _height, $ colors[' background ');// -----------------interference line--------------------------$theta          = 1; $thetac         = 7; $radius         = 16; $circles     =  20; $points         = 32;for  ($i  = 0,  $CP  =  ($circles  *  $points)  - 1;  $i  <  $cp;  $i +) {      $theta  +=  $thetac;     $rad  =  $radius  *  ($i   /  $points);     $x  =  ($rad  * cos ($theta))  +  $x _axis;      $y  =  ($rad  * sin ($theta))  +  $y _axis;      $theta  +=  $thetac;     $rad 1 =  $radius  *  (($i  +  1)  /  $points);     $x 1 =  ($rad 1 * cos ($theta))  +   $x _axis;     $y 1 =  ($rad 1 * sin ($theta))  +  $y _axis;     imAgeLine ($im,  $x,  $y,  $x 1,  $y 1,  $colors [' Grid ']);     $theta  - =  $thetac;}  --------------------------------------------------------------//  No font//  ($font _size >  5)  &&  $font _size = 5;//  $x  = mt_rand (0,  $img _width  /  ($length  / 3);//  $y  = 0;// for  ($i  = 0;  $i  <   $length;  $i + +) {//      $y  = mt_rand (0 ,  $img _height &NBSP;/&NBSP;2)//     imagestring ($im,  $font _size,  $x,  $y,  $word [$i],  $colors [' text ']);//      $x  +=  ($font _size * 2);//  }//  have font// x  the first character randomly in the front of the picture a small paragraph, followed by a character size of the width of// y  picture 1/2 to the bottom of the distance between 3px random ($font _size  > 30)  &&  $font _size = 30; $x  = mt_rand (0,  $img _width  /  ($length  / 1.5)) $y  =  $font _size + 2;for  ($i  = 0;  $i  <  $length;  $i + +) {     $y  = mt_rand ($img _height / 2,   $img _height - 3)     imagettftext ($im,  $font _size,  $angle,  $x,  $y,  $colors [' text '],  $font _path,  $word [$i]);     $x  += $ Font_size;} Draw Rectangular Box Imagerectangle ($im, 0, 0,  $img _width - 1,  $img _height - 1,  $colors [' border ']);//  Delete the previously saved picture $now = microtime (TRUE); $current _dir = opendir ($img _ Path);while  ($filename  = readdir ($current _dir)) {    if  (In_array ( substr ($filename,  -4),  array ('. jpg ',  '. png ')) &&  (Str_replace (Array ('. jpg ',  '). PNG '),  ',  $filename)  + 0.1)  <  $now) {          @unLink ($img _path $filename);    &nbsp}} @closedir ($current _dir);//  stitching the file path and saving $img_url =  rtrim ($img _url,  '/'). ' /'; $img _filename =  $now. JPG '; imagejpeg ($im,  $img _path. $img _filename); $img  =  '  "// imagedestroy ($im);// return array (' word '  => $ word,  ' time '  =>  $now,  ' image '  =>  $img,  ' filename '  => $ Img_filename);// echo  $img;//Notification browser is the PNG format header (' content-type:image/jpg ');//Output imagejpeg ($IM) in PNG format;// Destroy the image resource in memory Imagedestroy ($IM);


PHP Broken Code--CI 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.