当用户访问我的网站时,如何获得本地机器ip地址ipv4地址?

时间:2018-04-20 11:12:44

标签: php ip ipv4

每当用户访问我服务器上的网站时,如何获取本地机器IP地址ipv4地址?

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)

问题代码没有显示任何内容?

1 个答案:

答案 0 :(得分:0)

检查$_SERVER['REMOTE_ADDR'],我猜客户端IP就在那里