使用swoole_http_server的时候怎么判断pc还是移动端呢?

新手上路,请多包涵

我用apache 和 nginx 配合php判断都能生效的代码在swoole_http_server 里使用判断是不能正常使用的

阅读 2.6k
2 个回答

HttpRequest->$header

<?php
use Swoole\Http\Server;

$http = new Server("127.0.0.1", 9501);
$http->on('request', function ($request, $response) {
    $response->end($request->header['user-agent']);
});
$http->start();

你就用$request->header['user-agent']来判断就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进