简体   繁体   English

在Codeigniter中集成普通的php会话

[英]Integrating normal php session in codeigniter

I have been experiencing session in codeigniter but I have some failure since sometime I need to register session without using controller. 我一直在codeigniter中遇到会话,但是由于有时我需要在不使用控制器的情况下注册会话,所以我遇到了一些故障。 For instance When a facebook user login in my app using FACEBOOK SDK this plugins use normal php session, so when I try to get them in codeigniter controller I fail; 例如,当一个Facebook用户使用FACEBOOK SDK登录我的应用程序时,此插件使用普通的php会话,因此当我尝试在codeigniter控制器中获取它们时,我会失败; In other part when I register a session in a controller I will need to call the same session in other controllers or register base controller. 在另一部分中,当我在控制器中注册会话时,我将需要在其他控制器或注册基础控制器中调用同一会话。 Killing codeIgniter session does not remove SDK session and cookies. 终止codeIgniter会话不会删除SDK会话和cookie。 So How can I use normal session in CodeIgniter so that I don't loose SDK functionality. 因此,如何在CodeIgniter中使用普通会话,以免失去SDK功能。 Thanks. 谢谢。

A replacement of codeigniter's sessions is already available, It's called Native Sessions class, You just drop the files in their places & everything should work as expected. 已经可以使用codeigniter的会话的替代品,它称为Native Sessions类,您只需将文件放在它们的位置即可,一切都会按预期进行。

https://github.com/appleboy/CodeIgniter-Native-Session https://github.com/appleboy/CodeIgniter-Native-Session

The facebook wrapper was written as it is for this very reason. 正是出于这个原因,编写了Facebook包装器。 Managing data used with or by the base class is done in this wrapper. 在该包装器中管理与基类一起使用或由基类使用的数据。

After assigning the CI superglobal to the facebook class in the constructor 在将CI超全局变量分配给构造函数中的facebook类之后

$this->ci =& get_instance();

Replace all instances of 替换的所有实例

$_SESSION

With and the relevant information as it would have gone previously into $_SESSION 和以及相关信息,就像以前进入$ _SESSION一样

//Add data to the session
$this->ci->session->set_userdata();

//Remove data from the session
$this->ci->session->unset_userdata();

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

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