我应该使用CodeIgniter的哪个会话库? [英] Which session library should I use with CodeIgniter?

查看:126
本文介绍了我应该使用CodeIgniter的哪个会话库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用CI及其CI会话,但是我注意到,与基本的PHP会话: 相比,CI会话更加耗时。



我有一个数据数组,无论登录/注销名为 $ _ SESSION ['stats'] 然后我以这种形式在数组中存储数据:



$ _ SESSION ['stats'] ['last_page'] = $ _SERVER ['REQUEST_URI '];



当用户注销时,它将stats数组保存在变量中,清除会话,然后将其加载回新会话。



问题是,为了编辑last_page键,而不是上面的一行,我必须使用这个代码:

  $ stats = $ this-> CI-> session-> userdata('stats'); 
$ stats ['last_page'] = $ _SERVER [REQUEST_URI];
$ this-> CI-> session-> set_userdata('stats',$ stats);

这是我在CI会话中发现的一些烦恼之一,这让我感到不满意它作为我的会话处理程序。所以我的问题是:我应该使用CodeIgniter哪个会话系统? ...使用CI会话有什么原因吗?是否有一个CI库,你会建议?为什么不使用PHP会话?



感谢,



Lemiant

CI会话提供了一些额外的功能; ,例如每隔给定的时间(为了安全),IP地址跟踪,自动重新生成会话ID,



CI的会话机制将所有数据存储在cookie中。 PHP的本地会话机制存储在服务器端。每个都有它的优点/缺点。 Cookie只能保存4KB的数据,因此,如果您在会话PHP本地会话中存储大量数据可能会更好。



如果您决定要使用本机PHP会话使用会话混合(CI 1.7.2)



Session Hybrid使用本地PHP会话,可以在默认CI数据库中存储会话数据,是CI会话类的替代,只需要重写一个文件。



[*如果在 1.7.0之前使用CI版本,请尝试 PHPSession 本地会话]



附注:如果您选择继续使用CI会话,为了增加安全性,您可以将会话存储在数据库中并加密Cookie(请参阅会话首选项)。


I have recently started using CI and with it CI sessions, but I have noticed that one thing in particular is much more time consuming to do with CI sessions than with the base PHP sessions: Arrays.

I have an array of data that persists regardless of login/logout called $_SESSION['stats'], I then store data in that array in the form:

$_SESSION['stats']['last_page'] = $_SERVER['REQUEST_URI'];.

And when a user logs out, it saves the stats array in a variable, clears the session, and then loads it back into the new session.

The problem is that in order to edit the last_page key, instead of the one line above, I have to use this code:

$stats = $this->CI->session->userdata('stats');
$stats['last_page'] = $_SERVER["REQUEST_URI"];
$this->CI->session->set_userdata('stats', $stats);

This is one of a number of annoyances I find in CI sessions, which cause me to feel dissatisfied with it as my session handler. So my question is: Which session system should I use with CodeIgniter?... is there some reason for using CI sessions? Is there a CI library that you would suggest? Why not just use PHP sessions?

Thanks,

Lemiant

解决方案

CI sessions offers some extra functionality; such as auto regenerating the session id every given amount of time (for security), IP address tracking, and flashdata (session data that's cleared after it's read once).

CI's session mechanism stores all the data in a cookie. PHP's native session mechanism is stored server side. Each have it's advantages/disadvantages. Cookies can only hold 4KB of data, so if your storing large amounts of data in session PHP native sessions might be better.

If you decide to you want to use native PHP sessions use: Session Hybrid (CI 1.7.2)

Session Hybrid uses native PHP sessions, can store session data in the default CI db, is a drop-in replacement for CI’s session class, and only requires one file to be rewritten.

[* If using a CI version before 1.7.0 try PHPSession and Native Session]

Side note: If you choose to stay with CI's sessions, for additional security you can store sessions in a database and encrypt the cookies (see Session Preferences).

这篇关于我应该使用CodeIgniter的哪个会话库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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