2

I'm following an article to save PHP sessions in Redis rather than the filesystem (so I can share session with node.js)

I understand how session_set_save_handler works but i'm confused on how to set it up with the CodeIgniter framework? Should I extend the CI_Session class and put the session_set_save_handler in there?

1

2 Answers 2

1

Redis session is supported in Codeigniter version 3

Open and Edit

application/config/config.php

To enable Redis set session driver to "redis"

$config['sess_driver'] = 'redis';

Example of redis server path

redis://hostname:port or tcp://hostname:port

Set the value of sess_save_path localhost for local testing

$config['sess_save_path'] = 'tcp://localhost:6379';

To test Redis on your localhost.

Please refer to my answer on how to install Redis for Windows

Sign up to request clarification or add additional context in comments.

Comments

0

Store your session in database. In order to store sessions, you must first create a database table for this purpose. Here is the basic prototype (for MySQL) required by the session class:

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

SET

$config['sess_use_database'] = TRUE;

in config.php FILE.

Once enabled, the Session class will store session data in the DB.

Make sure you've specified the table name in your config file as well:

$config['sess_table_name'] = 'ci_sessions';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.