Prerequisites:
with these
- GEOIP (geoip.inc, geoip.dat etc)
- Signup for an account in www.ipinfodb.com
- Download the php class api HERE
- 1. put the geoip files (preferably in a folder) in root directory
- 2. edit the index.php of the root directory and replace these code
/* Store or website code */ $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ''; /* Run store or run website */ $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; Mage::run($mageRunCode, $mageRunType);
//########### GEOIP ############// $geoipPath = 'geoip.inc'; include($geoipPath); $gi = geoip_open("GeoIP/GeoIP.dat",GEOIP_STANDARD); $ip = $_SERVER['REMOTE_ADDR']; $country_code = geoip_country_code_by_addr($gi, $ip); if(strtoupper($country_code) != "NL"){ $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'en'; $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; Mage::run($mageRunCode, $mageRunType); }else{ $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'nl'; $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; Mage::run($mageRunCode, $mageRunType); }
Magento has auto store switcher using GEOIP function and there are many modules available on web, I have not saw this function anywhere before. Auto Store Switch is key factor in magento module that cannot provide others.
ReplyDeleteAlan Smith..
Magento Block IP address
Great tutorial! I also saw many modules for implementing this functionality, I myself use this one https://amasty.com/magento-geoip-redirect.html
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGreat Read! I am impressed on how you make your article easy to understand. I'll come back for more :D
ReplyDeleteJaps Buidon is a Social Media Specialist and belongs to a team of Magento Developer in Florida. For more tutorial and tips you can follow him here -> alwaysopencommerce.com