It's often useful to record the API client's IP address. PHP has long supported an easy way to retrieve the IP address using the
$_SERVER['REMOTE_ADDR'] variable. Keep in mind however that the client is sometimes operating behind a proxy, and that proxy might therefore assign the IP address to the
HTTP_X_FORWARDED_FOR header. PHP will additionally make this value available using the $_SERVER['HTTP_X_FORWARDED_FOR'] variable.
There is no additional configuration required to access PHP's global
$_SERVER variable array.
$ip = $_SERVER['REMOTE_ADDR']; $proxiedIP = $_SERVER['HTTP_X_FORWARDED_FOR'];