1

The below code i tried:

<?php
function get_ip_address(){
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
        if (array_key_exists($key, $_SERVER) === true){
            foreach (explode(',', $_SERVER[$key]) as $ip){
                $ip = trim($ip); // just to be safe

                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
                    return $ip;
                }
            }
        }
    }
}
$result = get_ip_address();
echo $result;
?>

It gives an ip address like : 1.23.75.70 It doesn't seems like client device's ip address. It shows the same ip address while executing on all devices.

I want to get the dynamic ip address of the client device where i am execuing this code.

Arunkumar
  • 23
  • 1
  • 10
  • When you say "client device IP" do you mean the internal network IP? I.e. the one typically assigned via DHCP? – apokryfos Jul 28 '16 at 14:12
  • @apokryfos yes internal network ip only – Arunkumar Jul 28 '16 at 14:13
  • That can only be done when the server is set up within the internal network. It is impossible otherwise unless the clients willingly disclose that information (which they don't). – apokryfos Jul 28 '16 at 14:18
  • You mean to say that it will work only on online server? @apokryfos – Arunkumar Jul 28 '16 at 14:21
  • 1
    No, I'm saying that the internal network IP is only available to other people who are INSIDE the internal network. It is not available to servers which are hosted outside the network. – apokryfos Jul 28 '16 at 14:27
  • As far as I know this information is not available outside the local network to anyone. – apokryfos Jul 28 '16 at 14:58
  • okay :) @apokryfos – Arunkumar Jul 28 '16 at 14:59
  • 1
    No, I'm saying that the internal network IP is only available to other people who are INSIDE the internal network. It is not available to servers which are hosted outside the network. @ArunKumar – Vigneshwaran T Sep 09 '16 at 09:30

0 Answers0