【发布时间】:2013-06-02 18:04:55
【问题描述】:
我正在构建一个表单 + 表单验证类,我还想在其中添加验证码。 验证码图像正在显示,但它没有在 $_SESSION 中存储任何内容。
我正在使用这个验证码脚本:
https://github.com/gesf/captcha.class.php
现在在我的控制器中我使用这个:
$data['regform']->addfield('user_captcha', 'Human verification', 'captcha', 'captcha' );
这会产生以下内容:
<label>
<span>Human verification</span>
<img name="user_captcha" src="http://www.websiteurl.com/dev/misc/captcha.php?c=1"><input type="text" name="user_captcha" value="" />
</label>
图像显示正常。但是我无法验证输入,因为它没有写入会话。现在在图像文件 captcha.php 中,它加载了 Captcha 类,并在这个类构造函数中尝试写入会话:
function Captcha($letter = '', $case = 5) {
$this->_capCase = $case;
if (empty($letter)) {
$this->StringGen();
} else {
$this->_capLength = strlen($letter);
$this->_capString = substr($letter, 0, $this->_capLength);
}
@session_start();
$_SESSION['asd'] = 'asd';
$_SESSION["CAPTCHA_HASH"] = sha1($this->_capString);
$this->SendHeader();
$this->MakeCaptcha();
}
我的会话总是空的。但是当我尝试以下操作时:
<?php $_SESSION['bleh'] = 'asd'?>
<?php echo $form; ?>
它将“bleh”添加到会话中,就像它应该的那样。
我真的不明白为什么它不会写入会话..
有人可以帮帮我吗?
谢谢!!
【问题讨论】:
-
你的应用程序总是调用 session_start() 吗?
-
是的,我的 index.php 文件包含一个 session_start