I'm new to stakoverflow, but I swear that I really searched a lot before ask here. In short, I've two browsers opened, and two PHP sessions, redis takes care of the session, but when I try to refresh the page the online user that refreshed the node.js server take the (maybe socket id?) of the refreshed one, and if I do a logout on the not refreshed one, the connection will close as the refreshed one.
I know, it's messy. I have to set a socket id array with also session together? Currently, I am storing each new connection in a room (to have private sockets), but I become to think that maybe I've to change something for make all work properly.
How you handle a refreshed page? Also because can happen that a user open another tab of same website, or a friend give a link and you visit that link, and you need the session id (ok) the saved user (ok) and the socket io socket (wrong in my case?). Maybe its because I don't know how to get the cookie outside this:
socket.on('connection', function(client) {
cookieManager = new co.cookie(client.request.headers.cookie);
clientSession.get("sessions/"+cookieManager.get("PHPSESSID"), function(error, result) {
if (error) {
console.log("error : "+error);
}
if (result != "") {
// if (result.toString() != "") {
console.log("PHP session id: " + cookieManager.get("PHPSESSID"));
//console.log(result.toString());
//console.log("print result: " + result); //warning! this will parse entire session, test only!
userData = JSON.parse(result);
}
}
}