There are 2 servers A and B. I have my php script in server B.
Now, the client sends some data to server A and server A sends it to server B.
I want to get the IP address on which the request came(that is server A). How can I do it using php?
If I use $_SERVER['REMOTE_ADDR'], I get the clients IP address.
If I use $_SERVER['SERVER_ADDR'], I get the null value.
$_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.”