Answer the question
In order to leave comments, you need to log in
Sec-Web-Socket-Accept header issue, how to fix?
Hello, help me fix it, I made a socket server in php, I try to connect to it through the program, but it says that the secwebsocketaccept header is wrong. The browser writes the same.
By the way, if anything, I connect to the socket at this address ws://aneme3.000webhostapp.com/server/s
impleworking/simpleworking.php
Here is the code to process and create this header :
<?php
$SecWebSocketKey=$_SERVER['HTTP_Sec_WebSocket_Key' ];
$SecWebSocketAccept = base64_encode(pack('H*', sha1($SecWebSocketKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
$response = "HTTP/1.1 101 Web Socket Protocol Handshake" .
"Upgrade: websocket" .
"Connection: Upgrade" .
"
header("HTTP/1.1 101 Web Socket Protocol Handshake\r\n");
header("Upgrade: websocket\r\n");
header("Connection: Upgrade\r\n");
header("Sec-WebSocket-Accept: $SecWebSocketAccept\r\n\r\n");
I just ask you not to suggest switching to node js, you don’t need a console either, you only need php.
Answer the question
In order to leave comments, you need to log in
There are suspicions that pack is not needed:
// SEC_KEY_UUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
// $key = Sec-WebSocket-Key header
$accept = \base64_encode(\sha1($key . self::SEC_KEY_UUID, true));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question