1

I set cookie with help of setcookie($name, $value) in php.

Then:

socket.on('connection', function(socket) {

    var parse = cookie.parse(socket.handshake.headers.cookie);
    console.log(parse);
}

And I receive only something like this

{ 'connect.sess': 's:j:{}.CoRLkkQvzo1011EOxT2IdmJh5rqejQ0m5dp0XGFCIz4' }

socket.handshake.headers.cookie doesn't store all of my cookie ?

Tony
  • 11
  • 1
  • 3
  • Cookies usually are not shared across different domains, I assume your cookie is bound to one domain (can be IP with Port) and then is not sent to another domain. – moka Oct 18 '13 at 10:07

1 Answers1

0

I recently had the same problem. The following links helped me solve my problem.

Community
  • 1
  • 1
Matthias Holdorf
  • 1,040
  • 1
  • 14
  • 19
  • 1
    Ok, thanks. But what about socket.handshake.headers.cookie ? As I saw in the second link, email was saved in the session from request params, e.g. req.param('email'). But I try to set cookie before socket.on('connection',....) and then try to get it from socket.handshake.headers.cookie. – Tony Oct 18 '13 at 19:08
  • Session data is stored server-side in NodeJS. A session is not stored in a cookie, but instead, the cookie (with its sid) is what tells the server which session is associated with the client. – Matthias Holdorf Oct 19 '13 at 07:09
  • I use socket.io to exchange information between two servers, e.g. between main site on one server and node.js on another server. As you see, I have different hosts. As I understand, http requests are not sended to node.js, because I use only socket.io for socket.emit and socket.on. I don't understand how session can help me ? But as far as I know, when client connects to the server on node js, e.g. socket.on('connection') event rises, client sends http reqiest with headers, that store clients cookie in socket.handshake.headers.cookie. – Tony Oct 19 '13 at 09:11
  • But as was mentioned before, cookies usually are not shared across different domains (I have two hosts). Therefore I need to try to set domain (node.js host) param in setcookie(). I think, I cant even set this sid, because users are not visit the site directly. – Tony Oct 19 '13 at 09:21
  • What do you think about this ? – Tony Oct 19 '13 at 09:23