Magento 2 Get Ip Address


Magento 2 Get Ip Address– Sometimes we need to get the Ip address programatically. Here in this tutorial we are going to explain how you can get current visitors IP.


Magento 2 Get Ip Address | Remote Address Example

You can get the remote ip address using object manager simply as below-

Magento 2 Get Ip Address Example:

        /** @var \Magento\Framework\ObjectManagerInterface */
	$objctManager = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $a */
	$remote = $objctManager->get('Magento\Framework\HTTP\PhpEnvironment\RemoteAddress');
	echo $remote->getRemoteAddress();

The above example will return the remote IP Address.


Advertisements

Add Comment

📖 Read More