Search code examples
phpcookieswebsocket

Websocket (wss) sending/receiving wrong cookie for my domain with /path/


Im connecting to my own ratchet php websocket server on the same domain as my https website,

I have existing (different) cookies on www.domain.com and www.domain.com/admin

If I type in console document.cookie when on www.domain.com/admin i see the right cookie.

If I type in console new WebSocket('wss://www.domain.com/admin','wamp') and then look at the webdev toolbar network section, click on the wss connection (status 101) and look at the cookie -> "request cookies" section it shows the www.domain.com cookie,

And on my server, where i work with the sent cookie, its the www.domain.com cookie rather than admin one.

Im wondering if it could be something to do with the upgrade request/process , or any other ideas.

Thanks


Solution

  • Ok, found the problem with the help of wireshark, both cookies are being sent (to either a normal http page get, or the websocket open), but as they have the same name, if you look at $_COOKIE you will only see one, but if you look at $_SERVER['HTTP_COOKIE'] you see both, a quirk of php.

    So it would seem the php websocket library cookie parser guzzlehttp httpRequest->getHeader('Cookie') is also loosing one.