Localhost显示IP 127,而不是127.0.0.1


localhost shows ip 127 instead of 127.0.0.1

嗯,我试着得到访问者的ip & &;有个有趣的问题。当我试图用简单的SERVER['REMOTE_ADDR']返回访问者的ip时,我得到的返回ip是127.0.0.1。但当我试着用支票的时候。我只得到了127分。下面是代码。

我在XAMPP本地服务器上使用php 5.5.9

<?php 
$http_client_ip = $_SERVER['http_client_ip'];
$http_forwareded_x_for= $_SERVER['http_forwareded_x_for'];
$http_remoteAdd= $_SERVER['REMOTE_ADDR'];
$ip_address;
echo $http_remoteAdd.'<br>';

if(!empty($http_client_ip)){
    $ip_address=$http_client_ip;
    echo "Its not empyt";
} else if (!empty($http_forwareded_x_for)) {
    echo "Its not emply";
    $ip_address=$http_forwareded_x_for;
} else  {
    $ip_address =$http_remoteAdd;
    echo 'its working. <br>';
}
echo 'Your ip address is: '+ $ip_address;
 ?>

这一行:

echo 'Your ip address is: '+ $ip_address;

$ip_address变成一个数字,特别是127.0。您想要连接,而不是添加:

echo 'Your ip address is: ' . $ip_address;