Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Get Remote IP Address in PHP
SUBMITTED BY:
Guest
DATE:
Aug. 25, 2012, 10:04 p.m.
FORMAT:
PHP
SIZE:
678 Bytes
Raw
Download
Tweet
HITS:
1590
Go to comments
Report
function getRemoteIPAddress() {
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
The above code will not work in case your client is behind proxy server. In that case use below function to get real IP address of client.
function getRealIPAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus