Get visitors IP in php

by barkkathulla 2013-08-08 16:06:54


<?PHP

function getUserIPDetails()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];

if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}

return $ip;
}
$user_ip = getUserIPDetails();
echo $user_ip; // Result IP address

?>
741
like
0
dislike
0
mail
flag

You must LOGIN to add comments