首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kohana Captcha模块

Kohana Captcha模块
EN

Stack Overflow用户
提问于 2013-02-22 04:17:14
回答 1查看 1.7K关注 0票数 0

我正尝试在Kohana3.3项目中使用kohana-captcha module。在验证之前,一切都很正常。

下面是我的代码示例:

代码语言:javascript
复制
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_User extends Controller_Template {

    public $template = "template";

    public function action_create()
    {
            if (isset($_POST['captcha']))
            {
                print $_POST['captcha'];
                print ">>>".Captcha::valid($_POST['captcha'])."<<<";
            }

            $captcha = Captcha::instance();

            $this->template->content = View::factory('user/create')
                ->bind('captcha', $captcha);
    }
}

?>

查看代码:

代码语言:javascript
复制
<form method="post" action="/user/create/" class="form-horizontal" id="form">
    <div class="control-group">
        <label class="control-label" for="inputCaptcha">
            <?=$captcha?>
        </label>
        <div class="controls">
          <input type="text" id="inputCaptcha" placeholder="Код с картинки" name="captcha">
          <span class="help-inline"></span>
        </div>
    </div>    
</form>

$_SESSION and $_COOKIE数组也是空的。Captcha::valid($_POST['captcha'])什么也没给我看。

例如,我看到一个带有"KX5R“验证码的图像,这是print_r($captcha)的结果:

代码语言:javascript
复制
Captcha_Alpha Object ( [driver:protected] => [response:protected] => MWXF [image:protected] => [image_type:protected] => png )

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-22 07:21:38

你应该检查你的验证码变量,在这里是‘POST’,是否等于验证码的实例。因此,您应该在验证Captcha时使用if语句之前初始化post对象。

如下所示:

代码语言:javascript
复制
$captcha = Captcha::instance();

$this->template->content = View::factory('user/create')
    ->set('captcha', $captcha);

if ($this->request->method() === Request::POST)
{
    if (Captcha::valid($_POST['captcha']))
        .. do something if captcha is OK
    else 
        ..do something if captcha is not OK 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15011408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档