简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM