4.* HTTP如何获取用户IP?

9raxdev

如题

1407 2 0
2个回答

blogdaren
$request->getRemoteIp();
  • blogdaren 2020-07-07

    补充下:这个是webman的玩法,workerman自身的用楼下@six的$connection->getRemoteIp();

six

和workerman 3.x 一样吧
$connection->getRemoteIp();

  • 9raxdev 2020-07-06

    嗯 谢谢,我一直在Request里面找,没找到

  • blogdaren 2020-07-06

    @7192: 4.x最大的变化之一是就是引入了随处可见的Request和Response对象,随处可见,怎么还找不到;另外$request->getRemoteIp(); 我一直都在用的好好的呢,立马试一下就完了。

  • 9raxdev 2020-07-07

    $this->onMessage = function ($connection, $request) {

            print_r($connection->getRemoteIp());
            print_r($request->getRemoteIp());

    }

    再三确认 确实没有

    Type: Error; Message: Call to undefined method Workerman\Protocols\Http\Request::getRemoteIp();

  • blogdaren 2020-07-07

    @7192: 哦哦汗~~,抱歉刚意识到我一直陷在webman环境了,webman是这样玩的:$request->getRemoteIp(); 其本质也是webman-framework框架的Request对象封装调用了workerman底层的$connection->getRemoteIp()方法,所以直接用$connection->getRemoteIp(),workerman内核版本对这个没有任何变化。

年代过于久远,无法发表回答
🔝