Codeigniter用户数据不可用 [英] Codeigniter userdata not available

查看:51
本文介绍了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.

这篇关于Codeigniter用户数据不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆