Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/10/2012, 19:17
Avatar de galexisg
galexisg
 
Fecha de Ingreso: julio-2012
Mensajes: 2
Antigüedad: 11 años, 10 meses
Puntos: 0
Respuesta: codigo para mostrar la IP local, IP pública, la IP del proxy y el hostname

prueba con este codigo

Código PHP:
Ver original
  1. function ObtenerIP()
  2.     {
  3.        $ip = "";
  4.        if(isset($_SERVER))
  5.        {
  6.            if (!empty($_SERVER['HTTP_CLIENT_IP']))
  7.            {
  8.                $ip=$_SERVER['HTTP_CLIENT_IP'];
  9.             }
  10.             elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  11.             {
  12.                 $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  13.             }
  14.             else
  15.             {
  16.                 $ip=$_SERVER['REMOTE_ADDR'];
  17.             }
  18.        }
  19.        else
  20.        {
  21.             if ( getenv( 'HTTP_CLIENT_IP' ) )
  22.             {
  23.                 $ip = getenv( 'HTTP_CLIENT_IP' );
  24.             }
  25.             elseif( getenv( 'HTTP_X_FORWARDED_FOR' ) )
  26.             {
  27.                 $ip = getenv( 'HTTP_X_FORWARDED_FOR' );
  28.             }
  29.             else
  30.             {
  31.                 $ip = getenv( 'REMOTE_ADDR' );
  32.             }
  33.        }  
  34.         // En algunos casos muy raros la ip es devuelta repetida dos veces separada por coma
  35.        if(strstr($ip,','))
  36.        {
  37.             $ip = array_shift(explode(',',$ip));
  38.        }
  39.        return $ip;
  40.     }

te retorna la ip

uso

Código PHP:
Ver original
  1. $ip = ObtenerIP();