php中国語検証コード



  
  
  
  
  1. <?php 
  2. header("content-type: image/png"); 
  3.   class yanzhengma{ 
  4.   public $str=" "//  
  5.   public $geshu=4;//  
  6.   public $img;// sourcer 
  7.   public function  __construct($geshu){ 
  8.     $this->geshu=$geshu//  
  9.    
  10.    public function yanzhengma($x,$y){ 
  11.     // x ,y  
  12.     $this->img=imagecreatetruecolor($x,$y);// ,  
  13.     $rand = strlen($this->str)-2; 
  14.     $rand = $rand/2;// 2  
  15.     $text_color=imagecolorallocate($this->img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//  
  16.     $text_color2=imagecolorallocate($this->img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//  
  17.      
  18.    $text=''
  19.    for($i=0;$i<$this->geshu;$i++){ 
  20.        $rand=mt_rand(0,$rand);//  
  21.        $text=$text.substr($this->str,$rand*2,2); 
  22.     } 
  23.      
  24.      
  25.     $text=iconv('gb2312''UTF-8'$text);//  
  26.     imagefill($this->img, 0, 0, $text_color2);//  
  27.     imagettftext ($this->img,20,1,10,30,$text_color,"simkai.ttf",$text);//  
  28.    //imagestring($img, 30, 40, 40, $text, $text_color);  
  29.     imagepng($this->img);//  
  30.     return $text;// , session 
  31.      
  32.   }  
  33.    
  34.   public function destory(){ 
  35.     imagedestroy($this->img);//  
  36.   } 
  37.    } 
  38.     
  39.    $imgnew yanzhengma(5); 
  40.    $text=$img->yanzhengma(200,40); 
  41.    file_put_contents('1.txt'$text)   ; 
  42.    $img->destory(); 
  43. ?>