I'm building a chat app in Node.js which is only accessible when a user is logged in via my Wordpress blog. My blog runs on port 80, the chat app on 3000.
I have followed this guide on sharing a session between node and PHP. I can get the data stored into Redis, but the PHPSESSID in Node does not match the Wordpress one, why?
EDIT
PHP - functions.php
function init_session() {
require('redisSessionHandler.php');
session_start();
echo session_id();
}
add_action('init', 'init_session', 1);
This prints out the following session ID: pmlmvsst770hj2qsjjm9gt6ja4
Node - index.js
var app = require("http").createServer(handler),
fs = require("fs"),
redis = require("redis"),
co = require("./cookie.js");
app.listen(7070);
function handler(req, res){
fs.readFile(__dirname + "/index.html", function(err, data){
if(err){
res.writeHead(500);
return res.end("Error loading index.html");
} else {
res.writeHead(200);
res.end(data);
}
});
var cookieManager = new co.cookie(req.headers.cookie),
clientSession = new redis.createClient();
console.log(cookieManager.get("PHPSESSID"));
clientSession.get("sessions/"+cookieManager.get("PHPSESSID"), function(error, result){
console.log(result);
});
}
This prints out the following session ID: cv4dsufrkjk29njbfcht0rq015
Here's a link to cookie.js: https://gist.github.com/nickreffitt/5005071