How can one accurately retrieve the client IP address when including a file from another server in PHP?

When including a file from another server in PHP, the $_SERVER['REMOTE_ADDR'] variable may not accurately retrieve the client's IP address due to the nature of the request. To accurately retrieve the client's IP address, you can use the $_SERVER['HTTP_X_FORWARDED_FOR'] variable, which contains the client's original IP address even when including files from another server.

if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $client_ip = $_SERVER['REMOTE_ADDR'];
}

echo "Client IP Address: " . $client_ip;