我试图使用PHP获取客户端的IP和MAC地址,但我无法得到它。我尝试了下面的代码,但它提供了错误的MAC地址 -
ob_start(); // Turn on output buffering
system(‘ipconfig /all’);
$mycom=ob_get_contents(); // Capture the output into a variable
ob_clean(); // Clean (erase) the output buffer
$findme = "Physical";
$pmac = strpos($mycom, $findme);
$mac=substr($mycom,($pmac+36),17); // Get Physical Address
答案 0 :(得分:0)
就像评论者在问题上说的那样,自从PHP在服务器上运行后,您将无法获得客户端MAC,但是您可以通过选中$_SERVER['REMOTE_ADDR']
或者用户是否在后面获取客户端IP代理,您可以使用$_SERVER['HTTP_X_FORWARDED_FOR']
答案 1 :(得分:0)
正如许多用户所提到的,它无法获得用户MAC_ADDRESS
。要获得用户ip,请尝试此
function getUserIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}