Reading the HTTP Request
وثائق API
Request Headers
Application Functions
Request Functions
Request Content
You are requesting this page from IP Address [98.84.18.52]; here are the request headers that your browser submitted.
Header | Submitted Value |
---|---|
Connection | Keep-Alive |
Host | fastsitephp.com |
Accept-Encoding | br,gzip |
If-Modified-Since | Sun, 24 Sep 2023 17:38:09 GMT |
Accept-Language | en-US,en;q=0.5 |
Accept | text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
User-Agent | CCBot/2.0 (https://commoncrawl.org/faq/) |
رمز المثال
$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);