CodeIgniter Forums
How to share session between NodeJs and PHP - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forum-17.html)
+--- Thread: How to share session between NodeJs and PHP (/thread-76093.html)



How to share session between NodeJs and PHP - Sercan - 04-14-2020

Hello,
I want to read a node.js session that can log into Codeigniter, but I can't.

Redis DB:


[Image: KycoLc.jpg]

[Image: 5Re0h8.jpg]


CI;

PHP Code:
$config['sess_driver'] = 'redis';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'tcp://localhost:6379?auth=XXXXXXXXXXXX&database=0&timeout=604800';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE


Node JS;

Code:
const createError = require('http-errors');
const express = require('express');
const session = require('express-session');
const redis = require('redis');

const redisClient = redis.createClient({
    host: 'localhost',
    auth_pass: "XXXXXXXXXXX"
});

const redisStore = require('connect-redis')(session);
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');

const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');

const app = express();

redisClient.on('error', (err) => {
    console.log('Redis error: ', err);
});

app.use(session({
    secret: 'sercan',
    name: 'ci_session',
    resave: false,
    saveUninitialized: true,
    cookie: {
        secure: false,
        maxAge: 1000 * 60 * 60 * 24 * 7
    },
    store: new redisStore({prefix: 'ci_session:', host: 'localhost', port: 6379, client: redisClient, ttl: 86400 })
}));