欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能示例

 更新時(shí)間:2017年01月03日 11:38:16   作者:EthanQ  
這篇文章主要介紹了php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能,結(jié)合實(shí)例形式分析了php中文驗(yàn)證碼功能的實(shí)現(xiàn)步驟與操作方法,包括圖形創(chuàng)建、編碼操作、session操作等相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)的簡(jiǎn)單中文驗(yàn)證碼功能。分享給大家供大家參考,具體如下:

img.php

<?php
session_start();
/*for($i=0;$i<4;$i++) {
  $rand .= dechex(rand(1,15));
}
$_SESSION[check_pic] = $rand;
*/
$image = imagecreatetruecolor(100, 30);
$bg = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 255, 255, 255);
//imagestring($image, rand(1,6), rand(3,60), rand(3,15), $rand, $color);
for($i=0;$i<3;$i++) {
  $color2 = imagecolorallocate($image, rand(0,255), rand(0,255),rand(0,255));
  imageline($image, rand(0,100), 0, 100, 30, $color2);
}
//rand() ---->0-max 不大于100
for($i=0;$i<200;$i++) {
  imagesetpixel($image, rand()%100, rand()%30, $color2);
}
//$str = iconv("gbk", "utf-8", "中");
$str = "中國(guó)";
$_SESSION[check_pic] = $str;
//解決中文,頁(yè)面本身為utf-8
$str = mb_convert_encoding($str, "html-entities","utf-8" );
//2:字體大小 3:傾斜角度 x , y 坐標(biāo)
imagettftext($image, 12, 0, 20, 20, $color, 'MSYH.TTF', $str);
//輸出圖片
header("Content-type: image/jpeg;charset=utf-8");
imagejpeg($image);
/*修改eclipse的配置,可以使得eclipse的新建項(xiàng)目的默認(rèn)編碼直接為UTF-8
在菜單欄的
Window->Preferences->General->Workspace->Text file encoding
將其改為UFT-8即可。*/
?>

sub.php

<?php
  header("Content-type: text/html;charset=utf-8");
  session_start();
  if($_POST[check]) {
    if($_POST[check]==$_SESSION[check_pic]) {
      echo "驗(yàn)證碼正確:".$_SESSION[check_pic];
    } else {
      echo "驗(yàn)證碼錯(cuò)誤:".$_SESSION[check_pic];
    }
  }
?>
<form action="" method="post">
  <img alt="" src="img.php"><br/>
  <input type="text" name="check"><br/>
  <input type="submit" value="提交">
</form>

運(yùn)行效果圖如下:

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語(yǔ)法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論