$_SERVER['SERVER_NAME']
and $_SERVER['HTTP_HOST']
should return the DNS name of the server. If you can use the DNS instead of the IP I think maybe you should try with one of these variables. Although, as mentioned earlier, if $_SERVER['SERVER_ADDR']
isn´t populated you probably have a faulty configuration.
Provide information about server, IIS/Apache, OS, PHP version, it might be easier to help.
Also, try echoing/logging $_SERVER['SERVER_ADDR']
on server A where the request comes in and see if you get a value from there because reading $_SERVER['SERVER_ADDR']
on server B should give you IP of server B. If you get a value on server A you can save/pass the value forward to server B in code (wherever your transaction from server A to B takes place).
"The IP address of the server under which the current script is executing."