Skip to content
PHP Logo

What is the potential issue with using getenv() to retrieve the host and request URI in PHP?

Using getenv() to retrieve the host and request URI in PHP may not always work as expected, especially in certain server configurations or environments. To ensure more reliable results, it is recommended to use the $_SERVER superglobal array to access these values instead.

php
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';