I am new to magento, I am trying to display our visitors country name with the flag in the header position
But cant able to do is as most of the api sites were providing ipaddress using http forward request in php which i found in google
which is not the safe way of doing it. Is there anyway we can able to use mage code for getting ipaddress and country names of the visiors, Please advice me guys
Check this link:
It might help you.
The code for getting IP address is implemented here
\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress on getRemoteAddress() method.
After getting the IP address using this, you can make a curl call to http://freegeoip.net/ website as JSON format. you will get the country name.
And for adding flags, you can use class names for the HTML tag to show each flag based on each country. More info on making a call is described here.