1

when I run my code I get this error

PHP Warning: log() expects parameter 1 to be float, string given in /opt/lampp/htdocs/x/websocket/server.php on line 2 PHP Fatal error: Uncaught Error: Call to undefined function getheaders()

my code

<?php 
log("Handshaking...");
list($resource,$host,$origin) = getheaders($buffer);
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
           "Upgrade: WebSocket\r\n" .
           "Connection: Upgrade\r\n" .
           "WebSocket-Origin: " . $origin . "\r\n" .
           "WebSocket-Location: ws://" . $host . $resource . "\r\n" .
           "\r\n";
$handshake = true;
socket_write($socket,$upgrade.chr(0),strlen($upgrade.chr(0)));

what's the wrong ?

dark night
  • 171
  • 4
  • 19

1 Answers1

0

Look at the doc: http://php.net/manual/en/function.log.php log is not for "Logs".

Try with file_put_contents().

for getheaders() the correct syntax is get_headers()

xxx
  • 1,153
  • 1
  • 11
  • 23
Bast
  • 369
  • 2
  • 12
  • you mean using file_put_contents("Handshaking..."); instead of log like that ? i get this error PHP Warning: file_put_contents() expects at least 2 parameters, 1 given in – dark night May 09 '17 at 08:35
  • No file_put_contents($filepath, $content); => http://php.net/manual/en/function.file-put-contents.php or you can use fopen(), fwrite() and fclose(). – Bast May 09 '17 at 08:37