Codeigniter用户数据不可用
我正在为我的项目使用CodeIgniter.我快结束了,现在无法更改会话引擎".我有验证码图片,用于在网址上发布评论:
I'm using CodeIgniter for my project. I'm near end and I cannot change session "engine" now. I have captcha image for comment posting on url:
example.com/captcha
和代码:
this->load->library('session');
header("Content-type: image/jpeg");
/*
* Image generation code...
*/
$this->session->set_userdata('captcha', strtolower($word));
imagejpeg($image);
imagedestroy($image);
通常在我提交表单时使用
Usually when I'm submitting a form I use
<img src="example.com/captcha" />
生成图像并设置用户数据.但是这一次不起作用.$ this-> session-> userdata('captcha')为空.
to generate image and set userdata. But this time it doesn't work. $this->session->userdata('captcha') is empty.
但是,如果我直接访问图像,则会设置sessiondata,并在下次提交时直接在图像/验证码上生成一个$ word.是什么原因造成的?
But if I visit image directly sessiondata is set and on next submit there is a $word which was generated on direct access of image/captcha. What could cause this?
图片位于带有"www"前缀的域上,而索引位于domain.com上.我通过为会话设置数据库来解决这个问题.我已经看到一页访问有两个条目具有不同的session_id.
The image was on domain with "www" prefix, while index was on domain.com. I figure this out by setting database for sessions. I've seen there were two entries for one page visit with different session_id.