Categories
PHP

Get visitor IP address – PHP

Simple code of the day:

function getIp(){//obtain the ip
		// if getenv results in something, proxy detected
		if (getenv('HTTP_X_FORWARDED_FOR')) {
			$ip=getenv('HTTP_X_FORWARDED_FOR');
		}
		else {// otherwise no proxy detected
			$ip=getenv('REMOTE_ADDR');
		}

		return $ip;
}

Anyway of doing this better?