简体   繁体   English

在websockets php中传递参数

[英]Pass parameters in websockets php

I seen a example on html5 websockets with php at here . 我在这里看到了html5和php上的示例。

I want to pass parameters in url. 我想在url中传递参数。 So I used like shown below in index.php 所以我使用了如下所示的index.php

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

And in server.php I used 在server.php中,我使用了

              $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. 如何在打开的websoket连接上将参数传递给server.php。

You can send parameter with socket.send() after handshake as follow: 您可以在握手后使用socket.send()发送参数,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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