PHP get clients IP Address (Whats My IP Address)

///PHP get clients IP Address (Whats My IP Address)

PHP get clients IP Address (Whats My IP Address)

Just a simple function to get someones IP, I know most people have a one liner for this, problem with that I found is sometimes you get invalid and or empty results. My little function aims to work around the common issues that may cause an IP to come back wrong and get it regardless.\r\n\r\nExample your ip is \r\n\r\nCode:\r\n
\r\nfunction getRealIpAddr()\r\n{\r\n	if(!empty($_SERVER['HTTP_CLIENT_IP']))\r\n	{\r\n		$ip=$_SERVER['HTTP_CLIENT_IP'];\r\n	}\r\n	elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))\r\n	{\r\n		$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];\r\n	}\r\n	else\r\n	{\r\n		$ip=$_SERVER['REMOTE_ADDR'];\r\n	}\r\n	return $ip;\r\n}\r\n\r\necho getRealIpAddr();\r\n
By |2014-01-05T10:26:23+00:00March 8th, 2012|Code, PHP|0 Comments

About the Author:

Not much to know about me, I'm a 35+ year old coder, geek, gamer..

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: