想讓驗(yàn)證內(nèi)容顯示在輸入框中,求教QAQ
自己試了一下 ,發(fā)現(xiàn)圖片生成的與輸入框中生成的不一樣?
有大佬能整個(gè)方法不QAQ
--------------------------point.php(生成圖片驗(yàn)證內(nèi)容)
<?php
class yanzhengma
{
? ? private $image;//$image變量為私有;
? ??
? ? //定義一個(gè)公有類(lèi)型的方法
? ? public function _chuangjianditu()
? ? {
? ? ? ? //創(chuàng)建一張底圖
? ? ? ? $this ->image = imagecreatetruecolor(200, 60);
? ? ? ? //為一幅圖像分配顏色
? ? ? ? $bgcolor=imagecolorallocate($this->image,255,255,255);
? ? ? ? //區(qū)域填充 imagefill()? 在 image 圖像的坐標(biāo) x,y(圖像左上角為 0, 0)處用 color
? ? ? ? //顏色執(zhí)行區(qū)域填充(即與 x, y 點(diǎn)顏色相同且相鄰的點(diǎn)都會(huì)被填充)。
? ? ? ? imagefill($this->image, 0, 0, $bgcolor);
? ? ? ??
? ? }
? ? public function font(){
? ? ? ? return "唧唧復(fù)唧唧木蘭當(dāng)戶織不聞機(jī)杼聲惟聞女嘆息問(wèn)女何所思問(wèn)女何所憶女亦無(wú)所思女亦無(wú)所憶昨夜見(jiàn)軍帖可汗大點(diǎn)兵軍書(shū)十二卷卷卷有爺名阿爺無(wú)大兒木蘭無(wú)長(zhǎng)兄愿為市鞍馬從此替爺征東市買(mǎi)駿馬西市買(mǎi)鞍韉南市買(mǎi)轡頭北市買(mǎi)長(zhǎng)鞭旦辭爺娘去暮宿黃河邊不聞爺娘喚女聲但聞黃河流水鳴濺濺旦辭黃河去暮至黑山頭不聞爺娘喚女聲但聞燕山胡騎鳴啾啾萬(wàn)里赴戎機(jī)關(guān)山度若飛朔氣傳金柝寒光照鐵衣將軍百戰(zhàn)死壯士十年歸歸來(lái)見(jiàn)天子天子坐明堂策勛十二轉(zhuǎn)賞賜百千強(qiáng)可汗問(wèn)所欲木蘭不用尚書(shū)郎愿馳千里足,送兒還故鄉(xiāng)";
? ? }?
? ? public function captcha_cn(){
? ? ? ? session_start();
? ? ? ??
? ? ? ? $fontface = 'F:\Demo\project\simkai.ttf';
//? ? ? ? ?$str = '唧唧復(fù)唧唧木蘭當(dāng)戶織不聞機(jī)杼聲惟聞女嘆息問(wèn)女何所思問(wèn)女何所憶女亦無(wú)所思女亦無(wú)所憶昨夜見(jiàn)軍帖可汗大點(diǎn)兵軍書(shū)十二卷卷卷有爺名阿爺無(wú)大兒木蘭無(wú)長(zhǎng)兄愿為市鞍馬從此替爺征東市買(mǎi)駿馬西市買(mǎi)鞍韉南市買(mǎi)轡頭北市買(mǎi)長(zhǎng)鞭旦辭爺娘去暮宿黃河邊不聞爺娘喚女聲但聞黃河流水鳴濺濺旦辭黃河去暮至黑山頭不聞爺娘喚女聲但聞燕山胡騎鳴啾啾萬(wàn)里赴戎機(jī)關(guān)山度若飛朔氣傳金柝寒光照鐵衣將軍百戰(zhàn)死壯士十年歸歸來(lái)見(jiàn)天子天子坐明堂策勛十二轉(zhuǎn)賞賜百千強(qiáng)可汗問(wèn)所欲木蘭不用尚書(shū)郎愿馳千里足送兒還故鄉(xiāng)';
? ? ? ? $str = $this->font();
? ? ? ? $strdb = str_split($str,3);
? ? ? ??
? ? ? ? $capth_code="";
? ? ? ? for($i=0;$i<4;$i++){
? ? ? ? ? ? $fontcolor=imagecolorallocate($this->image,rand(20,120),rand(20,120),rand(20,120));
? ? ? ? ? ? $index = rand(0,count($strdb)-1);
? ? ? ? ? ? $cn = $strdb[$index];
? ? ? ? ? ? $capth_code.=$cn;
? ? ? ? ? ? imagettftext($this->image, mt_rand(20,24), mt_rand(-60,60),(40*$i+20), mt_rand(25,45), $fontcolor, $fontface, $cn);
? ? ? ? }
? ? ? ? $_SESSION['AUTHCODE']=$capth_code;
? ? ? ??
? ? ? ??
? ? }
? ? //生成干擾元素
? ? public function point()
? ? {
? ? ? ? for($i=0;$i<200;$i++)
? ? ? ? {
? ? ? ? ? ? //為一副圖像分配顏色,隨機(jī)生成點(diǎn)的顏色
? ? ? ? ? ? $pointcolor = imagecolorallocate($this->image, rand(50,200), rand(50,200), rand(50,200));
? ? ? ? ? ? imagesetpixel($this->image,rand(1,199),rand(1,59),$pointcolor);
? ? ? ? }
? ? ? ? for($i=0;$i<3;$i++){
? ? ? ? ? ? //隨機(jī)生成線
? ? ? ? ? ? $linecolor = imagecolorallocate($this->image, rand(80,250), rand(80,250), rand(80,255));
? ? ? ? ? ? imageline($this->image,rand(1,199), rand(1,59), rand(1,199), rand(1,59), $linecolor);
? ? ? ? }
? ? }
? ? public function output(){
? ? ? ? header('content-type: image/png');
? ? ? ? imagepng($this->image);
? ? }
? ??
}
$ojb = new yanzhengma();
$ojb ->_chuangjianditu();
$ojb ->captcha_cn();
$ojb ->point();
$ojb ->output();
<?php
session_start();
---------------------------------------index.php(界面)
if (isset($_REQUEST['authcode'])) {
? ? if ($_REQUEST['authcode'] == $_SESSION['AUTHCODE']) {
? ? ? ? echo '<font color="green">驗(yàn)證成功</font>';
? ? } else {
? ? ? ? echo '<font color="red">驗(yàn)證失敗</font>';
? ? }
? ? exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>驗(yàn)證頁(yè)面</title>
</head>
<body>
<form method="post" action="./index.php">
<p>
驗(yàn)證碼內(nèi)容: <img id="point" border="1" src="./point.php?r=<?php rand();?>"
width="200" height="60">
</p>
<a href="javascript:viod(0)"
onclick="document.getElementById('point').src='./point.php?r='+Math.random()">看不清?</a>
<p>
請(qǐng)輸入驗(yàn)證碼:<input type="text" name="authcode" value="" />
</p>
<p>
<input type="submit" value="提交" style="padding: 6px 20px">
</p>
<p>
<input type="text" value="<?php echo $_SESSION['AUTHCODE'] ?>">
</p>
</form>
</body>
</html>