简体   繁体   English

PHP | 验证码不会写入$ _SESSION

[英]PHP | Captcha won't write to $_SESSION

i'm building a form + form validation class , and i also wanted to add captcha to this. 我正在建立一个表单+表单验证类,我也想为此添加验证码。 The captcha image is showing, however it itsn't storing anything in the $_SESSION. 验证码图像正在显示,但是它没有在$ _SESSION中存储任何内容。

I am using this captcha script: 我正在使用此验证码脚本:

https://github.com/gesf/captcha.class.php https://github.com/gesf/captcha.class.php

Now in my controller i use this : 现在在我的控制器中,我使用这个:

$data['regform']->addfield('user_captcha', 'Human verification', 'captcha', 'captcha' );

And that generates the following : 并生成以下内容:

<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>

The image is showing like it should. 图像显示应有的状态。 However i'm not able to validate the input because it's not writing to the session. 但是我无法验证输入,因为它没有写入会话。 Now in the image file captcha.php it loads the class Captcha , and in this class constructor it tries to write to the session : 现在,在图像文件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();

} }

My session always stays empty. 我的会议总是空着。 But when i try the following : 但是当我尝试以下内容时:

<?php $_SESSION['bleh'] = 'asd'?>

<?php echo $form; ?>

It adds 'bleh' to the session like it should. 它将“ bleh”添加到会话中,就像应该的那样。

I really can't see why it won't write to the session.. 我真的不明白为什么它不会写入会话。

could someone help me out ?? 有人可以帮我吗??

Thanks!! 谢谢!!

Make sure, that session_start() is called before any output for every single page. 确保在每个页面的任何输出之前调用session_start()。 As I can see, you are using @ operator, that shuts up some errors. 如我所见,您正在使用@运算符,它关闭了一些错误。 Can you remove it and tell us what does it output? 您能删除它并告诉我们它输出什么吗? Also, your sessiaon_start() call is somewhere in the middle of the script. 同样,您的sessiaon_start()调用位于脚本中间。 Perhaps there are some other output before that. 也许在那之前还有其他输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM