读取HTTP请求
API文档
请求报头
应用程序函数
请求函数
请求内容
您正在从IP地址[13.59.205.182]请求此页; 以下是您的浏览器提交的请求报头.
报头 | 提交值 |
---|---|
Host | fastsitephp.com |
Accept-Encoding | gzip, br, zstd, deflate |
User-Agent | Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) |
Accept | */* |
示例代码
$req = new \FastSitePHP\Web\Request();
// Return an array of all HTTP Request Headers Fields. Header names will be
// capitalized so the following names ['Content-type', 'Content-Type',
// and 'CONTENT-TYPE'] would all be returned by this function as
// 'Content-Type' for the key in the array.
$headers = $req->headers();
// Return the value of a Header Field sent with the HTTP Request.
// If not sent [null] will be returned. Keys are case-insensitive
// so the following all return the same value.
$value = $req->header('Content-Type');
$value = $req->header('CONTENT-TYPE');
// Using PHP built-in features without FastSitePHP or other frameworks Request
// Headers can be read from the PHP Superglobal $_SERVER Array.
// For example 'User-Agent' will be 'HTTP_USER_AGENT'. This applies to all
// headers except for 'Authorization', 'Content-Type', and 'Content-Length'.
// To read those three headers directly refer to FastSitePHP source code.
$name = 'HTTP_USER_AGENT';
$value = (isset($_SERVER[$name]) ? $_SERVER[$name] : null);
// When using PHP 7 or higher the null coalescing operator can be used.
$value = ($_SERVER[$name] ?? null);