I want to share a server session between a NodeJs application and PHP using Redis . I took most of the code from this gist .
NodeJs Code:
app.use(session({ store: new RedisStore({prefix: 'session:php:'}), name: 'PHPSESSID', secret: 'node.js' })); app.use(function(req, res, next) { req.session.nodejs = 'node.js!'; res.send(JSON.stringify(req.session, null, ' ') ); });
And he outputs:
{ "cookie": { "originalMaxAge": null, "expires": null, "httpOnly": true, "path": "/" }, "passport": {}, "nodejs": "node.js!" }
PHP code (I use redis-session-php and Predis ):
require('redis-session-php/redis-session.php'); RedisSession::start(); $_SESSION['php'] = 'php'; if (!isset($_SESSION["cookie"])) { $_SESSION["cookie"] = array(); } var_dump($_SESSION);
And he outputs:
array(2) { ["php"] => string(3) "php" ["cookie"] => array(0) { } }
Problem: I would expect both sessions to look the same, but they do not work (the application runs in the same domain). Setting values ββusing set() from Predis\Client works (but the values ββwill not be on the session variable). I found this code that I think will work using set() and get() , but I feel this will overly complicate the code.
Do you know what I am doing wrong?
N alex
source share