为什么Codeigniter不在数据库中保存我的自定义会话?(Why Codeigniter does not save my custom session on database?)

编程入门 行业动态 更新时间:2024-10-10 02:21:25
为什么Codeigniter不在数据库中保存我的自定义会话?(Why Codeigniter does not save my custom session on database?)

我无法使用codeigniter将我的自定义会话保存在数据库中,我不知道为什么。

这是我的config.php

$config['encryption_key'] = 'MY_KEY'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 0; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300;

在我的模型中我有这个:

foreach ($res as $user) { $usuario["name"] = $user->name; $usuario["lastname"] = $user->lastname; $usuario["date_birthday"] = $user->date_birthday; $usuario["date_register"] = $user->date_register; $usuario["last_season"] = $user->last_seasson; $usuario["email"] = $user->email; $usuario["contry"] = $user->contry; $usuario["sex"] = $user->sex; $usuario["role"] = $user->role; $usuario["status"] = $user->status; $usuario["idUsuario"] = $user->id; } $this->set_last_season($usuario["idUsuario"]); $this->session->set_userdata('usuario', $usuario);

在我的控制器中,我尝试查看我的会话:

var_dump($this->session->userdata('usuario'));

我用数据库在数据库中创建了会话表:

CREATE TABLE IF NOT EXISTS `ci_sessions` ( session_id varchar(40) DEFAULT '0' NOT NULL, ip_address varchar(45) DEFAULT '0' NOT NULL, user_agent varchar(120) NOT NULL, last_activity int(10) unsigned DEFAULT 0 NOT NULL, user_data text NOT NULL, PRIMARY KEY (session_id), KEY `last_activity_idx` (`last_activity`) );

所有这些代码都可以正常工作而无需保存数据库会话和使用cookie会话

拜托,我需要帮助....我不知道再试一次......谢谢大家

I can't save my custom session on database with codeigniter and i don't know why.

This is my config.php

$config['encryption_key'] = 'MY_KEY'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 0; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300;

And in my Model i have this:

foreach ($res as $user) { $usuario["name"] = $user->name; $usuario["lastname"] = $user->lastname; $usuario["date_birthday"] = $user->date_birthday; $usuario["date_register"] = $user->date_register; $usuario["last_season"] = $user->last_seasson; $usuario["email"] = $user->email; $usuario["contry"] = $user->contry; $usuario["sex"] = $user->sex; $usuario["role"] = $user->role; $usuario["status"] = $user->status; $usuario["idUsuario"] = $user->id; } $this->set_last_season($usuario["idUsuario"]); $this->session->set_userdata('usuario', $usuario);

And in my Controller, I try view my session with:

var_dump($this->session->userdata('usuario'));

And I created my session table in database with:

CREATE TABLE IF NOT EXISTS `ci_sessions` ( session_id varchar(40) DEFAULT '0' NOT NULL, ip_address varchar(45) DEFAULT '0' NOT NULL, user_agent varchar(120) NOT NULL, last_activity int(10) unsigned DEFAULT 0 NOT NULL, user_data text NOT NULL, PRIMARY KEY (session_id), KEY `last_activity_idx` (`last_activity`) );

All this code works fine without saving session on database and using cookie sessions

Please, i need help.... i don't know that try more... Thanks for all

最满意答案

好吧,我详尽地分析了我的应用程序的流程,我发现故障来自登录控制器重定向到任何其他控制器。 那时,正在失去会议的codeigniter。

我正在记录这一失败,并看到有更多的人受到影响,并且不相信这个执政的余烬没有得到解决。 因此,在Google彻底搜索之后,我发现了一篇有趣的文章描述了这个问题,并为codeigniter系统中包含的Sessions库文件提供了一个“补丁”。

我做的这个库是重用原始库的所有方法,但将它应用于本机会话的使用。 因此,控制器之间的会话通过并没有失败。

如果其他人遇到同样的问题,或者未来的开发人员将文章中的链接留在新库会话的代码中,该怎么办?

http://www.philsbury.co.uk/blog/code-igniter-sessions

Well I followed exhaustively analyzing the flow of my application, and I detected the fault came in the redirect from the login controller to any other controller. At that time, was losing the sessiones codeigniter.

I was documenting this failure, and saw that there were very many more people affected and did not believe that this ruling embers unresolved. So here after searching thoroughly in Google, I found an interesting article that was describing this problem and provided a "patch" for the Sessions library files included in codeigniter system.

This library I did was to reuse all the methods of the original library but applying it to a use of native sessiones. Thus the passage of sessiones between controllers did not fail.

What if someone else has had the same problem, or for future developers who have left the link in the article which is the code of the new library session.

http://www.philsbury.co.uk/blog/code-igniter-sessions

更多推荐

本文发布于:2023-08-05 16:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   数据库中   Codeigniter   save   database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!