How to Get IP Address of Magento 2 Visitor
In this blog you will perceive how to get IP address of guest in magento 2.
<?php
namespace\Module\Controller\DemoController;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
class DemoClass expands Activity {
confidential $remoteAddress;
public capability __construct(
Setting $context,
RemoteAddress $remoteAddress
) {
$this->remoteAddress = $remoteAddress;
parent::__construct($context);
}
public capability execute()
{
$ip = $this->remoteAddress->getRemoteAddress();
reverberation "Guest's IP = ".$ip;
}
}
This will show the IP address of the client when this regulator is hit.
References :
Comments
Post a Comment