时间:2021-07-01 10:21:17 帮助过:33人阅读
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();
}
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("未输入验证码");
}
}
}
6436
object(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生成的验证码呢?
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();
}
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("未输入验证码");
}
}
}
6436
object(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 "验证码正确!!";}
}
}