Get Server Environment Information in CakePHP4

Get Server Environment Information in CakePHP4

The following example will provide you with server & envronment information (some similar to php_info()).

In your controller or view:

//Example 1: Get all variables
$env = $this->request->getServerParams();
debug($env);

//Example 2: Get the host
$host = $this->request->getEnv('HTTP_HOST');

 

This will return the following variables:

debug($this->request->getServerParams());

REDIRECT_REDIRECT_STATUS
REDIRECT_STATUS
HTTP_HOST
HTTP_CONNECTION
HTTP_CACHE_CONTROL
HTTP_SEC_CH_UA
HTTP_SEC_CH_UA_MOBILE
HTTP_SEC_CH_UA_PLATFORM
HTTP_UPGRADE_INSECURE_REQUESTS
HTTP_USER_AGENT
HTTP_ACCEPT
HTTP_SEC_FETCH_SITE
HTTP_SEC_FETCH_MODE
HTTP_SEC_FETCH_USER
HTTP_SEC_FETCH_DEST
HTTP_REFERER
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_COOKIE
PATH
SystemRoot
COMSPEC
PATHEXT
WINDIR
SERVER_SIGNATURE
SERVER_SOFTWARE
SERVER_NAME
SERVER_ADDR
SERVER_PORT
REMOTE_ADDR
DOCUMENT_ROOT
REQUEST_SCHEME
CONTEXT_PREFIX
CONTEXT_DOCUMENT_ROOT
SERVER_ADMIN
SCRIPT_FILENAME
REMOTE_PORT
REDIRECT_URL
GATEWAY_INTERFACE
SERVER_PROTOCOL
REQUEST_METHOD
QUERY_STRING
REQUEST_URI
SCRIPT_NAME
PHP_SELF
REQUEST_TIME_FLOAT
REQUEST_TIME
ORIGINAL_REQUEST_METHOD
HTTP_X_REQUESTED_WITH

Share this Post