Server
Provides normalized HTTP server information, resolved scheme and host values, client IP information and access to server variables.
Use the Core controller
Application code must read server information through Core\Server rather than accessing
$_SERVER
directly. Runtime-aware scheme and host values are particularly important behind reverse proxies.
Client IP handling
getIp() may return a pseudonymized value depending on configuration; getRawIp()
returns the original resolved client IP. Forwarded headers must only be trusted behind properly
configured
proxies.
Example
$server = Registry::get(Server::class);
$host = $server->getHost();
$scheme = $server->getScheme();
Public API Reference
Core\Server
Class & Registry
Class:
Core\Server
Extends:
Core\Server\Base
use Core\Server;
use Core\Registry;
$server = Registry::get(Server::class);
| Method | Description |
|---|---|
init():void |
Initializes the server controller and loads client IP encryption settings for the active application or administration context. |
setEncryptIp(bool $encryptIp):void |
Enables or disables client IP anonymization. |
getEncryptIp():bool |
Returns whether client IP anonymization is enabled. |
getScheme():string |
Returns the normalized request scheme from the active APPNETOS runtime. |
getHost():string |
Returns the normalized request host without the port. |
getHostWithPort():string |
Returns the normalized request host including the port, when applicable. |
getBaseUrl():string |
Returns the runtime base URL constructed from the request scheme and host with port. |
getIp():string |
Returns the resolved client IP address or its HMAC SHA-256 hash when anonymization is enabled. |
getRawIp():string |
Returns the validated client IP address from forwarded headers or the remote address, or unknown if unavailable. |
getUserAgent():string |
Returns the client user agent or unknown if unavailable. |
get(string $key, mixed $default = null):mixed |
Returns a PHP server environment value by key, or the specified default if the key is not set. |
has(string $key):bool |
Checks whether a key exists in the PHP server environment. |
getAll():array |
Returns all PHP server environment values as an array. |