我正尝试在Kohana3.3项目中使用kohana-captcha module。在验证之前,一切都很正常。
下面是我的代码示例:
<?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);
}
}
?>查看代码:
<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)的结果:
Captcha_Alpha Object ( [driver:protected] => [response:protected] => MWXF [image:protected] => [image_type:protected] => png )有什么建议吗?
发布于 2013-02-22 07:21:38
你应该检查你的验证码变量,在这里是‘POST’,是否等于验证码的实例。因此,您应该在验证Captcha时使用if语句之前初始化post对象。
如下所示:
$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
}https://stackoverflow.com/questions/15011408
复制相似问题