用TP3.2架構在Verify控制器中產生驗證碼代碼如下:
public function verify_c() { $Verify = new \Think\Verify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = '0123456789'; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); }
在Verify控制器中輸出驗證碼如下:
public function pv() { if (!empty($_POST)) { $verify = new \Think\Verify(); $code = $_POST['code']; if (!empty($code)) { echo($code . "\n");// dump($code); if (!empty($verify)) { echo($verify); var_dump($verify); } else { echo("驗證碼為空白"); } } else { echo("未輸入驗證碼"); } } }
前台代碼如下:
輸入後提交,顯示如下:
6436object(Think\Verify)[6] protected 'config' => array (size=15) 'seKey' => string 'ThinkPHP.CN' (length=11) 'codeSet' => string '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY' (length=52) 'expire' => int 1800 'useZh' => boolean false 'zhSet' => string '們以我到他會作時要動國產的一是工就年階義... (length=4500) 'useImgBg' => boolean false 'fontSize' => int 25 'useCurve' => boolean true 'useNoise' => boolean true 'imageH' => int 0 'imageW' => int 0 'length' => int 5 'fontttf' => string '' (length=0) 'bg' => array (size=3) 0 => int 243 1 => int 251 2 => int 254 'reset' => boolean true private '_image' => null private '_color' => null
為什麼取不到TP產生的驗證碼呢?
回複內容:
用TP3.2架構在Verify控制器中產生驗證碼代碼如下:
public function verify_c() { $Verify = new \Think\Verify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = '0123456789'; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); }
在Verify控制器中輸出驗證碼如下:
public function pv() { if (!empty($_POST)) { $verify = new \Think\Verify(); $code = $_POST['code']; if (!empty($code)) { echo($code . "\n");// dump($code); if (!empty($verify)) { echo($verify); var_dump($verify); } else { echo("驗證碼為空白"); } } else { echo("未輸入驗證碼"); } } }
前台代碼如下:
輸入後提交,顯示如下:
6436object(Think\Verify)[6] protected 'config' => array (size=15) 'seKey' => string 'ThinkPHP.CN' (length=11) 'codeSet' => string '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY' (length=52) 'expire' => int 1800 'useZh' => boolean false 'zhSet' => string '們以我到他會作時要動國產的一是工就年階義... (length=4500) 'useImgBg' => boolean false 'fontSize' => int 25 'useCurve' => boolean true 'useNoise' => boolean true 'imageH' => int 0 'imageW' => int 0 'length' => int 5 'fontttf' => string '' (length=0) 'bg' => array (size=3) 0 => int 243 1 => int 251 2 => int 254 'reset' => boolean true private '_image' => null private '_color' => null
為什麼取不到TP產生的驗證碼呢?
不用你取得代碼,直接調用工具類中的check就可以驗證了
$verify = new ThinkVerify();
return $verify->check($code);
自動完成中這樣使用就更好了:
/** * 驗證驗證碼. * @param string $code 驗證碼. * @return bool */ protected function checkCode($code) { $verify = new \Think\Verify(); return $verify->check($code); }
ob_clean();//在初始化Verify前加上這個試試
$verify = new ThinkVerify();
public function verify_c() { ob_clean(); $Verify = new \Think\Verify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = '0123456789'; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); }
我自己解決了可以用以下來直接驗證
public function pv() { if (!empty($_POST)) { $verify = new \Think\Verify(); $code = $_POST['code']; if(!$verify->check($code)) { $this->error("驗證碼錯誤!"); return; }else{ echo "驗證碼正確!!";} } }