Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kuria/request-info
Get information about the current HTTP request
https://github.com/kuria/request-info
base-dir base-path forwarded host http https ip path-info php port request trusted-proxies url x-forwarded
Last synced: about 1 month ago
JSON representation
Get information about the current HTTP request
- Host: GitHub
- URL: https://github.com/kuria/request-info
- Owner: kuria
- License: other
- Created: 2019-01-25T15:49:03.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-07T10:02:39.000Z (over 1 year ago)
- Last Synced: 2024-11-25T08:42:15.547Z (about 2 months ago)
- Topics: base-dir, base-path, forwarded, host, http, https, ip, path-info, php, port, request, trusted-proxies, url, x-forwarded
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
Request info
############Get information about the current HTTP request.
.. image:: https://travis-ci.com/kuria/request-info.svg?branch=master
:target: https://travis-ci.com/kuria/request-info.. contents::
:depth: 3Features
********- getting request information:
- headers
- HTTPS detection
- client IP address
- scheme
- method
- host
- port
- URL
- base directory
- base path
- path info
- script name- trusted proxy header support (x-forwarded / forwarded)
- host validation (inc. defining specific trusted hosts or host patterns)
- optional HTTP method override supportRequirements
************- PHP 7.1+
Usage
*****All configuration and value retrieval is done via the static ``Kuria\RequestInfo\RequestInfo`` class.
Configuration
=============Trusted proxies
---------------By default all proxy headers are ignored. To trust select proxy headers, call ``RequestInfo::setTrustedProxies()``
with an appropriately configured ``TrustedProxies`` instance... code:: php
localhost:8080
[connection] => keep-alive
[cache-control] => max-age=0
[upgrade-insecure-requests] => 1
[user-agent] => Mozilla/5.0 (Example)
[accept] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[accept-encoding] => gzip, deflate, br
[accept-language] => en-US,en;q=0.9,cs;q=0.8
)Trusted proxy detection
-----------------------Check whether the request originated from a trusted proxy.
.. code:: php
20.30.40.50
[1] => 10.20.30.40
).. NOTE::
``RequestInfo::getClientIps()`` will return an empty array if the client IP addresses are not known (e.g. in CLI).
Method
------Get the request method. The method name will always be in uppercase.
Also see `HTTP method override`_.
.. code:: php
getFullHost()`` to get the host name with the port
number (if it is non-standard).Port
----Get the port number.
.. code:: php
`_ component for more information.
.. code:: php
build(), PHP_EOL,
"Scheme:\t", $url->getScheme(), PHP_EOL,
"Host:\t", $url->getHost(), PHP_EOL,
"Port:\t", $url->getPort(), PHP_EOL,
"Path:\t", $url->getPath(), PHP_EOL,
"Query:\t", json_encode($url->getQuery()), PHP_EOL;Example output:
::
URL: http://localhost:8080/test/index.php/foo?bar=baz
Scheme: http
Host: localhost
Port: 8080
Path: /test/index.php/foo
Query: {"bar":"baz"}Base directory
--------------Get base directory (without script name, if any). The returned path never ends with a "/".
.. code:: php