Codeigniter userdata not available

2019-08-30 09:24发布

问题:

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

and code:

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

to generate image and set userdata. But this time it doesn't work. $this->session->userdata('captcha') is empty.

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?

回答1:

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.