當前位置:首頁 » 編程語言 » 中文驗證碼php

中文驗證碼php

發布時間: 2022-06-14 02:52:29

1. php驗證碼插入中文,為什麼顯示還是方格,我已經做了編碼轉換了。字體也有的

因為 ahronbd.ttf 這一個不是中文字型檔,你換一個中文字型檔就可以了。

2. 如何用PHP生成驗證碼

php生成驗證碼,php驗證碼,php怎樣生成驗證碼?
工具/原料
這個驗證碼較實用,大家可以應用到項目中。
方法/步驟
1.
<?php
/*設置文件頭為圖片輸出*/
Header("Content-type:image/JPEG");

/*調用生成驗證碼函數*/
$checkcode=make_rand(4);

/**
*生成驗證碼字元
*@paramint$length驗證碼字元長度
*@returnstring
*/
functionmake_rand($length="32"){
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return$result;
}
2.
/*調用輸出驗證碼圖片函數*/
getAuthImage($checkcode,160,40);

/**
*生成驗證碼圖片
*@paramstring$text驗證碼字元
*/
functiongetAuthImage($text,$w,$y){
/*設置圖片的寬度和高度*/
$im_x=$w;
$im_y=$y;
/*創建圖片*/
$im=imagecreatetruecolor($im_x,$im_y);
$text_c=ImageColorAllocate($im,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c=ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im,16,13,$buttum_c);
3.
/*字體文件*/
$font='t1.ttf';
for($i=0;$i<strlen($text);$i++)
{
$tmp=substr($text,$i,1);
$array=array(-1,1);
$p=array_rand($array);
$an=$array[$p]*mt_rand(1,10);//角度
$size=28;
imagettftext($im,$size,$an,15+$i*$size,35,$text_c,$font,$tmp);
}

/*將字元寫入文件中*/
$distortion_im=imagecreatetruecolor($im_x,$im_y);
imagefill($distortion_im,16,13,$buttum_c);
for($i=0;$i<$im_x;$i++){
for($j=0;$j<$im_y;$j++){
$rgb=imagecolorat($im,$i,$j);
if((int)($i+20+sin($j/$im_y*2*M_PI)*10)<=imagesx($distortion_im)&&(int)($i+20+sin($j/$im_y*2*M_PI)*10)>=0){
imagesetpixel($distortion_im,(int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4),$j,$rgb);
}
}
}
4.
/*干擾元素點的數量*/
$count=160;
/*創建干擾元素點*/
for($i=0;$i<$count;$i++){
$randcolor=ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im,mt_rand()%$im_x,mt_rand()%$im_y,$randcolor);
}
/*創建干擾線條*/
$rand=mt_rand(5,30);
$rand1=mt_rand(15,25);
$rand2=mt_rand(5,10);
for($yy=$rand;$yy<=+$rand+2;$yy++){
for($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2;
imagesetpixel($distortion_im,$px+80,$py+$yy,$text_c);
}
}
5.
/*以PNG格式將圖像輸出到瀏覽器*/
ImagePNG($distortion_im);

/*銷毀圖像*/
ImageDestroy($distortion_im);
ImageDestroy($im);

3. php中文驗證碼的思路是怎樣的是在字元串里輸入很多個中文讓隨機還是怎麼樣

$keyword = $_GET ['q']; //獲取的q值是 "請選擇" $choose="請選擇"; if($keyword==$choose) echo "ok"; echo var_mp($keyword).var_mp($choose); //echo 的結果 $keyword=>string(9) "請選擇" $choose=

4. PHP中文驗證碼只有背景沒中文

中文字元串的截取要使用mb_substr()

// 設置編碼,在代碼107行之前加上
mb_internal_encoding("UTF-8");

// 110行
//$code.=substr($str,$Xi,2);
$code.=mb_substr($str,$Xi,2);

// 136行
//$codex=iconv("GB2312","UTF-8",substr($code,$i*2,2));
$codex=mb_substr($code,$i*2,2);

5. php 中文 驗證碼 亂碼、、、

樓主 我懷疑是編碼問題 請查看個頁面是否一致 都是UTF-8比如

6. php中文驗證碼無法顯示

session_start();
$image=imagecreatetruecolor(200,60);//創建畫布
$color=imagecolorallocate($image,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));//隨機顏色
//$color=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$color);//填充顏色
//中文驗證碼
$fontface="simhei.ttf";//確保相同目錄下有該字體
$strdb=array('好','多','人','在','學','習');
for($i=0;$i<4;$i++){
$fontsizecolor=imagecolorallocate($image,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
$codex=iconv("GB2312","UTF-8",$strdb[mt_rand(0,5)]);//iconv不能轉數組取任意下標
imagettftext($image,mt_rand(20,24),mt_rand(-30,30),(40*$i+20),mt_rand(30,35),$fontsizecolor,$fontface,$codex);//如果用$code的話就生成1+2+3+4是個漢字的驗證碼了

}

//干擾點
for($i=0;$i<200;$i++){
$pointcolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imagesetpixel($image,mt_rand(1,100),mt_rand(1,20),$pointcolor); //雪花
}
//干擾線
for($i=0;$i<3;$i++){
$linecolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imageline($image,mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),$linecolor);
}
ob_clean();
header("Content-type:image/png");
imagepng($image);
imagedestroy($image);

7. php中文驗證碼轉換編碼iconv出問題

你好,你的字體引用的格式不對,換成

$font = $_SERVER['DOCUMENT_ROOT'].'/icon/yw.ttf';

imagettftext($im, 12, 18, 20, 20, $te, $font,'hello');


字體要是ttf的哦,希望對你有用啊!一準就好了

8. PHP圖片中文驗證碼生成問題

重新寫了一下,這里不能print那個字元串..不然會出錯
因為啟動了session 之前不能有輸出
最終$_SESSION['yzm']就是圖片上的驗證碼..
--------------------
<?php
session_start();
$im = imagecreatetruecolor(80,30);
$bg = imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
for($i=0;$i<5;$i++)
{
$te2 = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,80),0,80,rand(0,30),$te2);
}
for($i=0;$i<200;$i++)
{
imagesetpixel($im,rand()%100,rand()%30,$te2);
}
srand((float) microtime() * 10000000);
$input = array("步","步","高","請","轉","到","圖","像","我","非","常","高","興");
$rand_keys = array_rand($input, 4);
$_SESSION['yzm'] = $t = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]];
imagettftext($im,12,0,10,20,$te,'stxingka.ttf',$t);
header("content-type: image/jpeg");
imagejpeg($im);
?>

9. php 中文驗證碼一般用什麼字體

1M左右的行嗎?下載地址不好發上來,看截圖吧,那個網站里再找找可能還有更小的字體文件。

10. thinkphp的驗證碼類庫,如果需要使用中文驗證碼,那麼需要將系統字體文件復制到

我的項目代碼:

<?php
publicfunctionverify_code(){
$verify=newThinkVerify();

$verify->__set('seKey',C('VERIFY_KEY'));
$verify->__set('useZh',true);
$verify->__set('bg',array(235,246,230));
$verify->__set('length',2);
$verify->__set('fontSize',14);
$verify->__set('imageH',40);
$verify->__set('imageW',70);
$verify->__set('code',get_word());
return$verify->entry(1);
}
?>

get_word方法是隨機獲取一個兩個字的詞。

另外,字體是TP自帶的。

目錄在:/ThinkPHP/Library/Think/Verify/

熱點內容
王者什麼東西需要二級密碼 發布:2024-05-03 03:26:11 瀏覽:766
網頁界面升級訪問 發布:2024-05-03 03:26:06 瀏覽:210
安卓區怎麼更改充電提示音 發布:2024-05-03 03:23:56 瀏覽:48
遺傳演算法圖像分割 發布:2024-05-03 03:16:27 瀏覽:801
外圓圓弧怎麼編程 發布:2024-05-03 03:13:59 瀏覽:213
如何在conda中安裝需要編譯的軟體 發布:2024-05-03 02:41:21 瀏覽:780
易語言垃圾清理源碼 發布:2024-05-03 02:40:34 瀏覽:182
滴滴蘋果安卓哪個派單量好 發布:2024-05-03 02:22:52 瀏覽:289
lua編程pdf 發布:2024-05-03 01:39:26 瀏覽:24
臍帶血存儲的三大忌 發布:2024-05-03 01:32:38 瀏覽:934