Joshna Gunturu
Joshna Gunturu

Reputation: 161

Pass parameters in websockets php

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.

Upvotes: 2

Views: 2489

Answers (1)

KyawLay
KyawLay

Reputation: 403

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

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

Upvotes: 1

Related Questions