Get the client IP address using PHP

I am going to share how to get the client IP address using PHP. You can use PHP inbuilt function to get IP address. We are using IP address for tracking purpose. IP address mostly you can use for fill the payment form. Because we could truck for Future. If the payment fails or any other reason.

Example

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;
}
echo getRealIpAddr();

Leave a Reply

Your email address will not be published. Required fields are marked *