How can the real IP address be determined for users accessing the internet through a proxy server in PHP?

When users access the internet through a proxy server, the server's IP address is typically displayed instead of the user's real IP address. To determine the real IP address of the user, you can check the HTTP headers for the 'X-Forwarded-For' header, which may contain the real IP address. If the 'X-Forwarded-For' header is not present, you can also check the 'REMOTE_ADDR' server variable to get the IP address.

// Check for 'X-Forwarded-For' header to get real IP address
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $real_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    // Get IP address from 'REMOTE_ADDR' server variable
    $real_ip_address = $_SERVER['REMOTE_ADDR'];
}

echo "Real IP Address: " . $real_ip_address;