Download the PHP package kuria/request-info without Composer

On this page you can find all versions of the php package kuria/request-info. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package request-info

Request info ############

Get information about the current HTTP request.

:depth: 3

Features

Requirements

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.

$trustedProxies = new TrustedProxies( ['192.168.1.10', '192.168.1.20'], // one or more IP adresses or subnets in CIDR notation TrustedProxies::HEADER_FORWARDED // which headers to trust (bit mask) );

RequestInfo::setTrustedProxies($trustedProxies);

Choosing which headers to trust

Trusted headers are a bitmask of the following constants:

ConstantAllowed headers
TrustedProxies::HEADER_FORWARDED TrustedProxies::HEADER_X_FORWARDED_FOR TrustedProxies::HEADER_X_FORWARDED_HOST TrustedProxies::HEADER_X_FORWARDED_PROTO TrustedProxies::HEADER_X_FORWARDED_PORT TrustedProxies::HEADER_X_FORWARDED_ALLForwarded X-Forwarded-For X-Forwarded-Host X-Forwarded-Proto X-Forwarded-Port X-Forwarded-*

Applications always behind a trusted proxy

If you are sure that an application will always be behind a trusted proxy, you can use $_SERVER['REMOTE_ADDR'] in place of a hardcoded IP address:

$trustedProxies = new TrustedProxies( [Server::require('REMOTE_ADDR')], TrustedProxies::HEADER_FORWARDED );

RequestInfo::setTrustedProxies($trustedProxies);

Trusted hosts

The request host is always validated according to the standards.

To restrict accepted hosts further, use the following methods:

// specific hosts (exact match) RequestInfo::setTrustedHosts([ 'www.example.com', 'cdn.example.com', ]);

// host patterns RequestInfo::setTrustedHostPatterns([ '{\w+\.example\.com$}AD', '{example-node-\d+$}AD', ]);

HTTP method override

By default, the X-HTTP-Method-Override header is ignored.

If you need to override the HTTP method via this header (e.g. because of restrictive firewall rules), you can enable its support:

RequestInfo::setAllowHttpMethodOverride(true);

Resetting configuration

To restore default RequestInfo configuration:

RequestInfo::reset();

Getting request information

Headers

Get all request headers as an array. Header names are lowercased and used as keys.

Example output:

Array
(
    [host] => 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.

if (RequestInfo::isFromTrustedProxy()) { // request is from a trusted proxy }

HTTPS detection

See whether the request uses HTTPS.

if (RequestInfo::isSecure()) { // request uses HTTPS }

Client IP address

Get the client IP address.

var_dump(RequestInfo::getClientIp());

Example output:

string(9) "127.0.0.1"

To get all known client IP addresses (ordered from most trusted to least trusted), use getClientIps():

print_r(RequestInfo::getClientIps());

Example output:

Array
(
    [0] => 20.30.40.50
    [1] => 10.20.30.40
)

Method

Get the request method. The method name will always be in uppercase.

Also see HTTP method override.

var_dump(RequestInfo::getMethod());

Example output:

string(3) "GET"


Scheme

Get the request scheme.

var_dump(RequestInfo::getScheme());

Example output:

string(4) "https"

Host

Get the host name.

Also see Trusted hosts.

var_dump(RequestInfo::getHost());

Example output:

string(9) "localhost"

Port

Get the port number.

var_dump(RequestInfo::getPort());

Example output:

int(80)

URL

Get the request URL. Returns an unique instance of Kuria\Url\Url.

See the kuria/url component for more information.

$url = RequestInfo::getUrl();

echo "URL:\t", $url->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 "/".

var_dump(RequestInfo::getBaseDir());

Examples:

URLBase directory
http://localhost/index.php http://localhost/index.php/page http://localhost/web/index.php http://localhost/we%20b/index.php(empty string) (empty string) /web /we%20b

Base path

Get base path (including the script name, if any). The returned path never ends with a "/".

var_dump(RequestInfo::getBasePath());

Examples:

URLBase path
http://localhost/index.php http://localhost/index.php/page http://localhost/web/index.php http://localhost/we%20b/index.php/index.php /index.php /web/index.php /we%20b/index.php

Path info

Get path info.

var_dump(RequestInfo::getPathInfo());

Examples:

URLPath info
http://localhost/index.php http://localhost/index.php/page http://localhost/web/index.php http://localhost/we%20b/index.php/foo%20bar(empty string) /page (empty string) /foo%20bar

Script name

Get the current script name.

var_dump(RequestInfo::getScriptName());

Example output:

string(18) "./public/index.php"

Internal cache

Most methods of the RequestInfo class cache their results internally. If you manipulate $_SERVER after already reading some request information, you will need to call RequestInfo::clearCache() to clear the cache.


All versions of request-info with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-filter Version *
kuria/url Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kuria/request-info contains the following files

Loading the files please wait ....