php中国語検証コード
- <?php
- header("content-type: image/png");
- class yanzhengma{
- public $str=" "; //
- public $geshu=4;//
- public $img;// sourcer
- public function __construct($geshu){
- $this->geshu=$geshu; //
- }
-
- public function yanzhengma($x,$y){
- // x ,y
- $this->img=imagecreatetruecolor($x,$y);// ,
- $rand = strlen($this->str)-2;
- $rand = $rand/2;// 2
- $text_color=imagecolorallocate($this->img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//
- $text_color2=imagecolorallocate($this->img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//
-
- $text='';
- for($i=0;$i<$this->geshu;$i++){
- $rand=mt_rand(0,$rand);//
- $text=$text.substr($this->str,$rand*2,2);
- }
-
-
- $text=iconv('gb2312', 'UTF-8', $text);//
- imagefill($this->img, 0, 0, $text_color2);//
- imagettftext ($this->img,20,1,10,30,$text_color,"simkai.ttf",$text);//
- //imagestring($img, 30, 40, 40, $text, $text_color);
- imagepng($this->img);//
- return $text;// , session
-
- }
-
- public function destory(){
- imagedestroy($this->img);//
- }
- }
-
- $img= new yanzhengma(5);
- $text=$img->yanzhengma(200,40);
- file_put_contents('1.txt', $text) ;
- $img->destory();
- ?>