2

I seen a example on html5 websockets with php at here.

I want to pass parameters in url. So I used like shown below in index.php

              var wsUri = "ws://localhost:9000/demo/server.php?name=Jhon";  
              websocket = new WebSocket(wsUri); 

And in server.php I used

              $user = $_REQUEST['name'];

Then I got error

              Undefined index:name in server.php

Similarly I tried with session but it too didn't worked.

How can I pass parameters to server.php on websoket connection opened.

Joshna Gunturu
  • 161
  • 1
  • 2
  • 13

1 Answers1

1

You can send parameter with socket.send() after handshake as follow:

    var msg = {
    name: "jhon",
    otherparam:"value"
    };
    websocket.send(JSON.stringify(msg));
KyawLay
  • 403
  • 2
  • 10