How can the PHP code provided be improved to accurately retrieve the original IP address instead of the proxy IP?

The issue of retrieving the original IP address instead of the proxy IP can be solved by checking if certain HTTP headers are present in the request and using them to determine the correct IP address. One common header to check is 'X-Forwarded-For', which contains the original client IP address when a request passes through a proxy server. By checking and prioritizing these headers, we can accurately retrieve the original IP address.

if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

echo "Original IP Address: " . $ip_address;