Client IP at Magento

I need the IP address from which the user is viewing the current page

and i m using

echo $_SERVER['REMOTE_ADDR'];

and he shows me 127.0.0.1

+3
source share
4 answers

Here is the Magento function to get the client IP address:

echo Mage::helper('core/http')->getRemoteAddr();

getRemoteAddr()also accepts a boolean parameter. When false(by default), it will return the IP address as a string in common decimal decimal notation (for example, 192.168.0.1). When trueit returns the IP in decimal notation - a 32-bit integer. See IPv4 Address Representations for an understanding of the formats.

+20
source

Magento () () (localhost), , , PHP $_SERVER['REMOTE_ADDR'] 127.0.0.1 ( ::1).

, 127.0.0.1 IPv4 localhost.

. " " RFC 5735:

127.0.0.0/8 - -. , , . 127.0.0.1/32 loopback.

+1

: Mage::helper('core/http')->getRemoteAddr();

ip-, '127.0.0.1'

Mage::helper('core/http')->getRemoteAddr(true);, (2130706433)

0

-, :

$ips = explode (',', $_SERVER ['HTTP_X_FORWARDED_FOR']); $ ip = trim ($ ips [count ($ ips) - 1]);

0
source

All Articles