How can I get the client's IP address in a PHP webservice?

simon picture simon · Sep 17, 2009 · Viewed 12.1k times · Source

I have developed a PHP webservice. I would like to log all incoming connections of the WS clients, which are consuming this web service. How can I obtain the client's IP address? The value of

$_SERVER['HTTP_CLIENT_IP']
seems to be always empty.

Answer

Tom Haigh picture Tom Haigh · Sep 17, 2009

This should be what you want:

$_SERVER['REMOTE_ADDR']

The IP address from which the user is viewing the current page.

http://php.net/manual/en/reserved.variables.server.php