Source Code



Get Public IP Address

  • anonymous
  • Aug 15' 14
  • PHP
  • 4
  • 257
  • United States

this script to get public ip address: However, sometimes this does not return the correct IP address of the visitor, so we can use some other server variables to get the IP address. The below both functions are equivalent with the difference only in how and from where the values are retrieved. getenv() is used to get the value of an environment variable in PHP.

 

<?php

public function publicIP()
{
$ip = getenv('HTTP_CLIENT_IP')?:		getenv('HTTP_X_FORWARDED_FOR')?:	getenv('HTTP_X_FORWARDED')?:		getenv('HTTP_FORWARDED_FOR')?:		getenv('HTTP_FORWARDED')?:		getenv('REMOTE_ADDR');

return $ip;
}

?>
  • Tags : public, ip address, simple
comments powered by Disqus

Related Code

Getting Country Name From Ip Address Using GeoIP Plugin



Category