Friday, 15 April 2011

php - Writing a Magento GeoIP store redirect, problems with sharing links -


I currently have a Magento project where the client wants a fairly simple GeoIP solution, we tried some modules but all were heavy Due to the causes of dirty and other places.

I ended it using the GOIP php library and .dat files and just make a statement in index.php, redirecting to / us and / eu folders to other users who had index.php files , Which used to load relevant stores. It looks like

  / ########### GeoOP ############ $ geoipPath = 'contains / geoip.inc' ; ($ GeoipPath); $ Gi = geoip_open ("Include / GeoIP.dat", GeoIP Andandered); $ Ip = $ _SERVER ['REMOTE_ADDR']; $ Country_code = geoip_country_code_by_addr ($ gi, $ ip); $ EuArray = array ('DE', 'FR', 'AT', 'BE', 'HR', 'CA', 'CZ', 'DK', 'EE', 'FI', 'GR' HU ',' is ',' IE ',' IT ',' LU ',' MD ',' MC ',' NL ',' No ',' PL ',' PT ',' RO ',' Ru '' s', 'SI', 'ES', 'SE', 'CH', 'U.A.', 'VA'); What if ($ countrycode on stropper) == "US") {$ mageRunCode = isset ($ _ SERVER ['MAGE_RUN_CODE']) is that? $ _SERVER ['MAGE_RUN_CODE']: 'us_site'; $ MageRunType = isset ($ _ SERVER ['MAGE_RUN_TYPE'])? $ _SERVER ['MAGE_RUN_TYPE']: 'Website'; Dana :: Run ($ mageRunCode, $ mageRunType); } Otherwise (in_array (strtoupper ($ country_code), $ euArray)) $ $ mageRunCode = isset ($ _ server ['MAGE_RUN_CODE'])? $ _SERVER ['MAGE_RUN_CODE']: 'EU_site'; $ MageRunType = isset ($ _ SERVER ['MAGE_RUN_TYPE'])? $ _SERVER ['MAGE_RUN_TYPE']: 'Website'; Dana :: Run ($ mageRunCode, $ mageRunType); } And {$ mageRunCode = isset ($ _ SERVER ['MAGE_RUN_CODE'])? $ _SERVER ['MAGE_RUN_CODE']: ''; $ MageRunType = isset ($ _ SERVER ['MAGE_RUN_TYPE'])? $ _SERVER ['MAGE_RUN_TYPE']: 'Store'; Dana :: Run ($ mageRunCode, $ mageRunType); }   

This works well when sending the newsletter and in such a way that it also has a link

When a U.S. / EU customers click on the link, then they redirect it to the homepage, anybody know any way to get into this round?

Thanks

If you have found other stores installed on sub-directories, Can not you redirect them to other stores and add the URI?

Take your code above:

  if (on the stropper ($ countrycode) == "US") {header ('location: http://example.com/us '. $ _SERVER [' REQUEST_URI ']); } Otherwise (in_array (stratuper ($ countrycode), $ euArray) {header ('location: http://example.com/eu'. $ _SERVER ['REQUEST_URI']); } And {$ mageRunCode = isset ($ _ SERVER ['MAGE_RUN_CODE'])? $ _SERVER ['MAGE_RUN_CODE']: ''; $ MageRunType = isset ($ _ SERVER ['MAGE_RUN_TYPE'])? $ _SERVER ['MAGE_RUN_TYPE']: 'Store'; Dana :: Run ($ mageRunCode, $ mageRunType); }    

No comments:

Post a Comment