0

how do I get local machine IP address ipv4 address whenever user visit my website on the server?

function getLocalIP(){
exec("ipconfig /all", $output);
    foreach($output as $line){
        if (preg_match("/(.*)IPv4 Address(.*)/", $line)){
            $ip = $line;
            $ip = str_replace("IPv4 Address. . . . . . . . . . . :","",$ip);
            $ip = str_replace("(Preferred)","",$ip);
        }
    }
return $ip;
}

echo $ip = getLocalIP(); //This will return: 192.168.x.x (Your Local IP)

The problem code is not showing anything?

Graham
  • 7,431
  • 18
  • 59
  • 84

1 Answers1

0

check $_SERVER['REMOTE_ADDR'], I gues client ip is there

Егор Лебедев
  • 1,161
  • 1
  • 10
  • 26