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.
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.
This should be what you want:
$_SERVER['REMOTE_ADDR']
The IP address from which the user is viewing the current page.
You might try
<?php
var_dump($_SERVER);
to see all vars. But that actually also depends on the backend your script is running at. Is that Apache?
This worked for me.
http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html
Actually, I would suggest using this function to cover all of your bases, such as people using proxies, shared networks etc.:
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}