1

i used following code to display remote ip address

    $ip = $_SERVER["REMOTE_ADDR"];
    echo $ip;

and the following code also

     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();  

but both code display this result ::1

plzzzzz help me friends! how to get remote IP address?

DRAJI
  • 1,829
  • 8
  • 26
  • 45
  • 1
    You should stick with `$_SERVER["REMOTE_ADDR"]`. Other fields can be easily spoofed. Also read [this Q](http://stackoverflow.com/questions/3699454/should-ip-serverremote-addr-return-1-on-a-mamp-localhost), it may help – nice ass Jun 06 '13 at 11:27
  • You are accessing that script through a webserver right ? And not command line ? (yes.. it happens :) – Damien Overeem Jun 06 '13 at 11:30
  • 3
    You're getting an IP address, it's just an IPv6 one ... – HamZa Jun 06 '13 at 11:32
  • DRAJI. Is your problem resolved? If so.. accept an answer.. – Damien Overeem Jun 06 '13 at 20:04
  • in localhost, it display like ` ::1`, But in live site it displays correct format with that same coding, Thank You for your valuable response guys! – DRAJI Jun 07 '13 at 05:20

3 Answers3

9

Try this

//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);  
Padmanathan J
  • 4,614
  • 5
  • 37
  • 75
  • Thank you for your response @Nathan Srivi. In local host only it displays like that. But when i moved into live site,that problem was solved. Thank you – DRAJI Jul 27 '13 at 04:36
  • Remember that is you're using cloudflare you may use `$_SERVER['HTTP_CF_CONNECTING_IP']`. More info in [this topic](https://stackoverflow.com/a/14985633/529403). – Ricardo Martins Sep 02 '20 at 00:31
2

In Magento, you have to get the remove/customer IP address in the following way

Print Mage::helper('core/http')->getRemoteAddr(true);
Vinoth Babu
  • 6,724
  • 10
  • 36
  • 55
0

It's the IPV6 version of localhost.

Switch to ipv4 (if neccesary) by changing your apache listen port (in httpd.conf) to Listen 0.0.0.0:80 and restart apache. This forces the webserver to use the ipv4 ip. $_SERVER['REMOTE_ADDR'] will now return 127.0.0.1.

See a discussion about this here: http://board.issociate.de/thread/489575/SERVERquotREMOTEADDRquot-returning-1.html

Damien Overeem
  • 4,487
  • 4
  • 36
  • 55