-3

My web page offline return lpv4 format ip address

But uploading on server(online) it will show a lpv6 ip address.

Main Purpose is to get client pc ip address on my website

localhost wamp ip address

  1. 0.0.somthing

Webhost ip address get is 2402:3a80:872:94a:d99f:d430:3dae:980

<?php
   echo $_SERVER['REMOTE_ADDR'];
?>
l.b.vasoya
  • 1,028
  • 7
  • 22

3 Answers3

0

You can get it like this :

   <?PHP

function getUserIP()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}


$user_ip = getUserIP();

echo $user_ip; // Output IP address [Ex: 177.87.193.134]


?>
0

If you are using PHP version 5.3 or higher you can do like this

$host= gethostname();
$ip = gethostbyname($host);

This works when you are running a stand-alone script,not through the web server

Rahul
  • 1,587
  • 1
  • 8
  • 18
0

I've been using this on my page. hope it works.

 public function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

echo get_client_ip();
kim de castro
  • 299
  • 4
  • 18