sanwebe / Chat-Using-WebSocket-and-PHP-Socket

Simple Example of Chat system using PHP socket and HTML5 WebSockets
184 stars 129 forks source link

Undefined index: Sec-WebSocket-Key for wss connection #3

Open factorin-j opened 7 years ago

factorin-j commented 7 years ago

I'm unable to connect to the socket server if the client is changed to wss and accessed via https

PHP Notice:  Undefined index: Sec-WebSocket-Key in /path/to/repository/server.php on line 140
varun-naharia commented 6 years ago
$headers = array();
    $lines = preg_split("/\r\n/", $receved_header);
    foreach($lines as $line)
    {
        $line = chop($line);
        if(preg_match('/\A(\S+): (.*)\z/', $line, $matches))
        {
            $headers[$matches[1]] = $matches[2];
        }
    }

    $secKey = $headers['Sec-WebSocket-Key']; // This line giving error.

Please fix this

n1ce-0ne commented 2 years ago

@factorin-j @varun-naharia theirs a server code update to use: stream_socket_server() see here> https://www.php.net/manual/en/function.stream-socket-server.php#125540 this fixes ssl/https but also since ive adapted my code i no longer get these errors