Reputation: 161
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
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