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

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

问题描述

我最近开始使用CI与它CI会话,但我注意到一个特别的一点是耗费更多的时间做与CI的会话比基本PHP会话:阵列的。

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.

我有数据的数组仍然存在,无论所谓的登录/注销 $ _ SESSION ['统计'] ,然后我在表单数组中存储数据:

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 ['统计'] ['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.

的问题是,为了编辑last_page键,上述代替一行,我必须使用此code:

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);

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

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?

谢谢,

Lemiant

推荐答案

CI会议提供了一些额外的功能; 如自动重新生成会话ID每一个时间给量(安全性),IP地址跟踪和 flashdata 的(它读取一次之后的清除会话数据)。

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的会话机制店在cookie中的所有数据。 PHP的本地会话机制是存储服务器端。每个人都有它的优势/劣势。 Cookies只能存储4KB的数据,因此,如果您存储大量的会话PHP自身的会话数据,可能会更好。

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.

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

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

会话Hybrid采用原生PHP会话,可以存储在默认CI DB会话数据,是一个简易替换为CI的会话类,只需要一个文件被改写。

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.

[*如果使用CI版本的的1.7.0尝试 PHPSession 本地会话]

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

附注:如果你选择留在CI的会议,额外的安全性,你可以存储在数据库中的会话和加密的cookies(见的Session preferences )。

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天全站免登陆