每当用户访问我服务器上的网站时,如何获取本地机器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)
问题代码没有显示任何内容?
答案 0 :(得分:0)
检查$_SERVER['REMOTE_ADDR']
,我猜客户端IP就在那里