Ratchet: Get header value in "onOpen" function.

Created on 29 Apr 2016  路  5Comments  路  Source: ratchetphp/Ratchet

Client is sending values in header while handshaking.
I want to receive those value in "onOpen" function of "Chat.php". (as in example)
Can you please tell me how to do that?
Thanks.

question

Most helpful comment

I looked for a good time the solution, and I ended up finding. If it can help someone, I'll post it here:

public function onOpen(ConnectionInterface $conn) {        
        $headers = $conn->httpRequest->getHeaders();
        // ...
}

All 5 comments

public function onOpen(ConnectionInterface $conn)
you can then access the request object by:
$conn->WebSocket->request
from there on you get access to the header, cookies, etc.

PHP Notice: Undefined property: Ratchet\Server\IoConnection::$WebSocket in C:\x
ampp\htdocs\NearPeople\socket\NearChat.php on line 18

Notice: Undefined property: Ratchet\Server\IoConnection::$WebSocket in C:\xampp\
htdocs\NearPeople\socket\NearChat.php on line 18
PHP Notice: Trying to get property of non-object in C:\xampp\htdocs\NearPeople\
socket\NearChat.php on line 18

Notice: Trying to get property of non-object in C:\xampp\htdocs\NearPeople\socke
t\NearChat.php on line 18
NULL
onOpen: 30onMessage: 30 || msg: GET / HTTP/1.1
Host: 192.168.9.156:8080
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: 1a5YB/+iy69hqVakoQHqDQ==

PHP Notice: Trying to get property of non-object in C:\xampp\htdocs\NearPeople\
socket\Parser.php on line 13

Notice: Trying to get property of non-object in C:\xampp\htdocs\NearPeople\socke
t\Parser.php on line 13

Its giving me this error.

Can you post some source to assist in troubleshooting please?

I looked for a good time the solution, and I ended up finding. If it can help someone, I'll post it here:

public function onOpen(ConnectionInterface $conn) {        
        $headers = $conn->httpRequest->getHeaders();
        // ...
}

I looked for a good time the solution, and I ended up finding. If it can help someone, I'll post it here:

public function onOpen(ConnectionInterface $conn) {        
        $headers = $conn->httpRequest->getHeaders();
        // ...
}

its actually on "Ratchet\WebSocket\WsServer" line 112
as a guzzle object

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lugia101101 picture Lugia101101  路  7Comments

lubatti picture lubatti  路  6Comments

piotrchludzinski picture piotrchludzinski  路  5Comments

Opice picture Opice  路  4Comments

DmitryPorotov picture DmitryPorotov  路  3Comments