i just use php and node.js and after search i found only way for Authentication with user
so first thing i change my php session save bath to redis
and this is my code for insert session
session_name("userID");
session_start();
$_SESSION["username"] = "hello world";
this is image for redis and its show the session
and here is my my browser cookie
i just want to Authentication the session on node.js so if user login in php ... node.js send data to user else refuse user ... or send data from mysql by node.js
so here i build node.js server
every thing its work good i require socket on client and i send data to server ..
every time user send value by socket i want to Authentication the user if user login php (session found in redis) send data to user else ... send u must login first
my problem on how to check if the session in redis by node.js
You need to query your redis db for the session information, with something like given below
//user.js
Add user and its session in appsession hash map in redis
exports.addUserSession = function (redisClient,userId,sessionId,callback){
redisClient.hset('appsession',sessionId,userId,function(err,response){
callback(err,response);
});
};
exports.validateUserSession = function (redisClient,userId,sessionId,callback){
redisClient.hget('appsession',sessionId,function(err,response){
if(response==userId)
{
callback(err,true);
}
else
{
callback(err,false);
}
});
};
you can then use the same method in your code to check whether user session is available or not. E.g
var session = require(./user.js );
socket.on("selector", function( data) {
sessionID = data.handshake.session;
USERNAME = socket.username;
session.validateUserSession(redisClient,USERNAME,sessionID,function(err,response){
// Do other processing if session is valiated
}
});
Hope it helps.