我使用以下代码显示远程IP地址
$ip = $_SERVER["REMOTE_ADDR"];
echo $ip;
以及以下代码
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
elseif(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
elseif(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress; } echo get_client_ip();
但两个代码都会显示此结果::1
答案 0 :(得分:8)
试试这个
//Get Visitor's information
$visitorData = Mage::getSingleton('core/session')->getVisitorData();
// printing visitor information data
echo "<pre>"; print_r($visitorData); echo "</pre>";
// user's ip address (visitor's ip address)
$remoteAddr = Mage::helper('core/http')->getRemoteAddr(true);
// server's ip address (where the current script is)
$serverAddr = Mage::helper('core/http')->getServerAddr(true);
答案 1 :(得分:2)
在Magento中,您必须按以下方式获取删除/客户IP地址
Print Mage::helper('core/http')->getRemoteAddr(true);
答案 2 :(得分:0)
这是localhost的IPV6版本。
通过将您的apache监听端口(在httpd.conf中)更改为Listen 0.0.0.0:80
并重新启动apache,切换到ipv4(如果需要)。这会强制Web服务器使用ipv4 ip。 $ _SERVER ['REMOTE_ADDR']现在将返回127.0.0.1。
请在此处查看有关此问题的讨论:http://board.issociate.de/thread/489575/SERVERquotREMOTEADDRquot-returning-1.html