-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,188
  • 8
  • 23
  • Possible duplicate of [How to get Real IP from Visitor?](https://stackoverflow.com/questions/13646690/how-to-get-real-ip-from-visitor) – jeremykenedy Mar 12 '18 at 16:30
  • Look at all the copied and pasted answers from https://stackoverflow.com/questions/13646690/how-to-get-real-ip-from-visitor Try googling the information you want. – jeremykenedy Mar 12 '18 at 16:31

4 Answers4

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,617
  • 1
  • 9
  • 18
0

In the wamp are generate ipv4 formate ip address

And

Webserver are generate temporary ipv6 formate ip address

l.b.vasoya
  • 1,188
  • 8
  • 23
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
  • 6
  • 19