Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
14 lines (12 loc) · 458 Bytes

7.5.2 - 使用Chrome访问服务器会产生2次请求.md

File metadata and controls

14 lines (12 loc) · 458 Bytes

使用Chrome访问服务器会产生2次请求

这是因为Chrome浏览器会自动请求一次favicon.ico,所以服务器会收到2Request,通过打印$req->server['request_uri'] 能看到请求的URL路径。

屏蔽 favicon.ico

$uri = $req->server['request_uri'];
if ($uri == '/favicon.ico') {
	$res->status(404);
	$res->end();
}

上述示例代码中,$req 为 Http\Request 对象,$res 为 Http\Response 对象