I am building an application with codeigniter and implementing nodejs for things in real time. I want to check if a user is registered with nodejs. With the code below, I can get the codeigniter session id on the nodejs server:
var server = require('https').createServer(options, function(request, response){ var cookies=(function(str){ var result={}; str.split(/;\s+/).forEach(function(e){ var parts=e.split(/=/,2); result[parts[0]]=parts[1]||''; }); return result; })(request.headers.cookie), sessionCookieName='ci_session', sessionId=cookies[sessionCookieName]||''; console.log(sessionId); }).listen(8080);
The codeigniter session is stored in the database, and encryption is set to true. And sess_match_ip = TRUE, sess_match_useragent = TRUE;
Now my question is: what is a good way to check if a user is logged in? I installed the node-mysql client. I know that CI does something like:
SELECT * FROM (`ci_sessions`) WHERE `session_id` = 'blabla' AND `ip_address` = '127.0.0.1' AND `user_agent` = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2'
How to decrypt a session id and check if it matches with db?
Thanks in advance
George
georgesamper
source share