Post a comment
The default IP address retrieval site is often overwhelmed by requests and does not respond timely (20 minutes off every hour :-( ).
I currently use some of the sites mentioned (and tested) with minor variations :-) :
- https://myexternalip.com/raw
- http://api.ipify.org
- http://ipecho.net/plain
No problems anymore.
$ nano myip.php
<?php
function getVisitorIp()
{
// Recogemos la IP de la cabecera de la conexión
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ipAdress = $_SERVER['HTTP_CLIENT_IP'];
}
// Caso en que la IP llega a través de un Proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ipAdress = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
// Caso en que la IP lleva a través de la cabecera de conexión remota
else
{
$ipAdress = $_SERVER['REMOTE_ADDR'];
}
return $ipAdress;
}
echo getVisitorIp();
?>