Validating the Webhook S2S
Last updated
// Function to get the real client IP when behind AWS ELB/ALB
function get_client_ip() {
// Check if X-Forwarded-For header exists
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// Split the X-Forwarded-For header into an array
$forwarded_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
// The first IP in the list is the real client IP (AWS specific)
$client_ip = trim($forwarded_ips[0]);
} else {
// Fallback to REMOTE_ADDR if X-Forwarded-For is not present
$client_ip = $_SERVER['REMOTE_ADDR'];
}
return $client_ip;
}