开发者

size of session in codeigniter

开发者_StackOverflow

How do I increase the size of the session framework CodeIgniter?

The standard size is 04 kb


It's got nothing to do with the codeigniter session, 4kb of data is the maximum size a cookie can hold.

To hold more data use a database (see "Saving Session Data to a Database" in http://codeigniter.com/user_guide/libraries/sessions.html).


Don't store large amounts of data in a session; it will be loaded into the script's memory on every request.

Use files or databases instead, connecting the data to the session using the session ID.


Yes, you will need to use a database. Yes, the 4kb limit is a browser limit for cookie sizes, as picked by Netscape a decade ago. It's generally a good practice to keep cookies small anyways, since every request header to an object on a server (for the same domain) will send this cookie.

Also, a good tip for CodeIgniter concerning database session table's, set the type to MEMORY, so that the sessions are stored in RAM instead of disk, which makes your site quicker (less disk reads when accessing the site). You'll lose the session data when the server reboots, but pending a reboot, that sort of information usually isn't too useful anyway.

SQL to create the CodeIgniter MySQL table:

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

CodeIgniter PHP options (in application/config/config.php):

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$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;


@all it is even not a good practice to hit db again & again for common data though Session could serve for this. I recommend to use PHP Native session for this purpose see here how you can use PHP Native Sessions in CI Replacing CI session with PHP Native Session

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜