onConnect怎样获取浏览器信息

zhqing

没有HTTP_USER_AGENT浏览器信息
怎样获得?
$worker->onConnect = function (TcpConnection $connection) {
$connection->send(obCache(function ()use($connection){
ps($_SERVER);//
}));
};

1271 3 0
3个回答

Tinywan

请贴出你的完整代码

  • 暂无评论
keytehu

在onWebSocketConnect里获取

$worker->onWebSocketConnect = function($connection) {
    var_dump($_SERVER);
};
  • zhqing 2022-03-04

    <?php
    require __DIR__ . '/vendor/autoload.php';

    use Workerman\Connection\TcpConnection;
    use Workerman\Worker;

    require_once __DIR__ . '/vendor/autoload.php';

    $worker = new Worker('websocket://0.0.0.0:6767');
    $worker->name = "Websocket Proxy";
    $worker->count = 4;
    $worker->onConnect = function (TcpConnection $connection) {
    //想在这个位置获取浏览器头部信息User-Agent
    var_dump($_SERVER);
    };
    Worker::runAll();

  • zhqing 2022-03-04

    $_SERVER中没有

  • czf 2022-03-07

    手册不是写有不支持!

walkor 打赏

@keytehu 是对的,在onWebSocketConnect 里获取浏览器信息。onConnect 完成tcp三次握手后触发的,这时候还没有数据穿出,无法获得http头信息。onWebSocketConnect是在websocket协议握手后出发的,已经传输了http头数据。

$worker->onWebSocketConnect = function($connection) {
    var_dump($_SERVER);
};

手册 https://www.workerman.net/doc/workerman/appendices/about-websocket.html#WebSocket%E5%8D%8F%E8%AE%AE%E6%8F%A1%E6%89%8B

  • 暂无评论
年代过于久远,无法发表回答
×
🔝