How can environment variables be accessed in PHP scripts for server-side information retrieval?

To access environment variables in PHP scripts for server-side information retrieval, you can use the $_SERVER superglobal array. This array contains key-value pairs of environment variables set by the server. You can access specific environment variables by using their key names within the $_SERVER array.

$server_ip = $_SERVER['SERVER_ADDR'];
$server_name = $_SERVER['SERVER_NAME'];

echo "Server IP Address: $server_ip <br>";
echo "Server Name: $server_name";