ADNREV Posted September 18, 2019 Share Posted September 18, 2019 (edited) hi :! please anyone help me , i want to redirect users from specific country to another Url ? i found this code , but i don't Know if it works , or where to put this code public function hookDisplayHeader() { $this->redirect(); } public function redirect(){ include_once(_PS_GEOIP_DIR_.'geoipcity.inc'); $gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD); $records = geoip_record_by_addr($gi, Tools::getRemoteAddr()); $URL_P = $_SERVER['REQUEST_URI']; $pais = $records->country_code; if ($pais == 'AD' | $pais == 'AT' | $pais == 'BE' | $pais == 'BG' | $pais == 'HR' | $pais == 'CY' | $pais == 'CZ' | $pais == 'DK' | $pais == 'EE' | $pais == 'FI' | $pais == 'FR' | $pais == 'DE' | $pais == 'GR' | $pais == 'HU' | $pais == 'IS' | $pais == 'IE' | $pais == 'IT' | $pais == 'LT' | $pais == 'LU' | $pais == 'MT' | $pais == 'NL' | $pais == 'NO' | $pais == 'PL' | $pais == 'RO' | $pais == 'SK' | $pais == 'SI' | $pais == 'SE' | $pais == 'CH' | $pais == 'TR' ){ $pais = 'CE'; } if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/BotLink|ahoy|AlkalineBOT|anthill|appie|arale|araneo|AraybOt|ariadne|arks|ATN_Worldwide|Atomz |bbot|Bjaaland|Ukonline|borg\-bot\/0\.9|boxseabot|bspider|calif|christcrawler|CMC\/0\.01|combine|confuzzledbot|CoolBot|cosmos| Internet Cruiser Robot|cusco|cyberspyder|cydralspider|desertrealm, desert realm|digger|DIIbot|grabber|downloadexpress|DragonBot| dwcp|ecollector|ebiness|elfinbot|esculapio|esther|fastcrawler|FDSE|FELIX IDE|ESI|fido|H�m�h�kki|KIT\-Fireball|fouineur|Freecrawl| gammaSpider|gazz|gcreep|golem|googlebot|AdsBot-Google|Googlebot-Image|Googlebot-News|Google-Structured-Data-Testing-Tool|pagespeed|insights|griffon|Gromit|gulliver|gulper|hambot|havIndex|hotwired|htdig|iajabot|INGRID\/0\.1|Informant| InfoSpiders|inspectorwww|irobot|Iron33|JBot|jcrawler|Teoma|Jeeves|jobo|image\.kapsi\.net|KDD\-Explorer|ko_yappo_robot|label\-grabber| larbin|legs|Linkidator|linkwalker|Lockon|logo_gif_crawler|marvin|mattie|mediafox|MerzScope|NEC\-MeshExplorer|MindCrawler|udmsearch|moget| Motor|msnbot|muncher|muninn|MuscatFerret|MwdSearch|sharp\-info\-agent|WebMechanic|NetScoop|newscan\-online|ObjectsSearch|Occam|Orbsearch\/1\.0| packrat|pageboy|ParaSite|patric|pegasus|perlcrawler|phpdig|piltdownman|Pimptrain|pjspider|PlumtreeWebAccessor|PortalBSpider|psbot|Getterrobo\-Plus| Raven|RHCS|RixBot|roadrunner|Robbie|robi|RoboCrawl|robofox|Scooter|Search\-AU|searchprocess|Senrigan|Shagseeker|sift|SimBot|Site Valet|skymob| SLCrawler\/2\.0|slurp|ESI|snooper|solbot|speedy|spider_monkey|SpiderBot\/1\.0|spiderline|nil|suke|http:\/\/www\.sygol\.com|tach_bw|TechBOT| templeton|titin|topiclink|UdmSearch|urlck|Valkyrie libwww\-perl|verticrawl|Victoria|void\-bot|Voyager|VWbot_K|crawlpaper|wapspider|WebBandit\/1\.0| webcatcher|T\-H\-U\-N\-D\-E\-R\-S\-T\-O\-N\-E|WebMoose|webquest|webreaper|webs|webspider|WebWalker|wget|winona|whowhere|wlm|WOLP|WWWC|none|XGET| Nederland\.zoek|AISearchBot|woriobot|NetSeer|Nutch/i', $_SERVER['HTTP_USER_AGENT'] ) ){ }else { $dominiourl =$_SERVER['SERVER_NAME']; switch ($pais) { case 'ES': if ($dominiourl != 'dominio.com' || $dominiourl == 'ce.domain.com' || $dominiourl == 'uk.dominio.com' || $dominiourl == 'usa.dominio.com') header("Location: https://domain.com".$URL_P.""); break; case 'PT': if ($dominiourl != 'dominio.com' || $dominiourl == 'ce.domain.com' || $dominiourl == 'uk.dominio.com || $dominiourl == 'usa.dominio.com') header("Location: https://domain.com".$URL_P.""); break; case 'CE' : if ($dominiourl != 'ce.dominio.com' || $dominiourl == 'uk.domain.com' || $dominiourl == 'usa.dominio.com' || $dominiourl == 'dominio.com') header("Location: https://ce.domain.com".$URL_P.""); break; case 'US': if ($dominiourl != 'usa.dominio.com' || $dominiourl == 'uk.domain.com' || $dominiourl == 'ce.dominio.com' || $dominiourl == 'dominio.com') header("Location: https://usa.domain.com".$URL_P.""); break; case 'GB' : if ($dominiourl != 'uk.dominio.com' || $dominiourl == 'ce.domain.com' || $dominiourl == 'usa.dominio.com' || $dominiourl == 'dominio.com') header("Location: https://uk.domain.com".$URL_P.""); break; case 'AU': if ($dominiourl != 'usa.dominio.com' || $dominiourl == 'uk.domain.com' || $dominiourl == 'ce.dominio.com' || $dominiourl == 'dominio.com') header("Location: https://usa.domain.com".$URL_P.""); break; default : if ($dominiourl != 'usa.dominio.com' || $dominiourl == 'uk.domain.com' || $dominiourl == 'ce.dominio.com' || $dominiourl == 'dominio.com') header("Location: https://usa.domain.com".$URL_P.""); break; } } } Thanks Edited September 18, 2019 by ADNREV (see edit history) Link to comment Share on other sites More sharing options...
vividusdesigns Posted September 18, 2019 Share Posted September 18, 2019 where did you find this code ? In third party module ? I think turning geolocation in prestashop can help you. Link to comment Share on other sites More sharing options...
ADNREV Posted September 18, 2019 Author Share Posted September 18, 2019 6 minutes ago, vividusdesigns said: where did you find this code ? In third party module ? I think turning geolocation in prestashop can help you. i found this in tuto , but as he said it's a module Link to comment Share on other sites More sharing options...
ADNREV Posted September 18, 2019 Author Share Posted September 18, 2019 (edited) i don't i just a newbies in prestashop , i migrate my woocommerce website to prestashop , i already asked 5 questions before but no one help , i solved all problem by myself , but with this one i tried several time ... Edited September 18, 2019 by ADNREV (see edit history) Link to comment Share on other sites More sharing options...
vividusdesigns Posted September 18, 2019 Share Posted September 18, 2019 You do not have to do anything with code. Just enable Geolocation by IP address and see if it solve your problem. Link to comment Share on other sites More sharing options...
ADNREV Posted September 18, 2019 Author Share Posted September 18, 2019 (edited) 11 minutes ago, vividusdesigns said: You do not have to do anything with code. Just enable Geolocation by IP address and see if it solve your problem. i already activate Geolocation by IP, but i need to make this module installable in prestashop 1.7 Edited September 18, 2019 by ADNREV (see edit history) Link to comment Share on other sites More sharing options...
vividusdesigns Posted September 18, 2019 Share Posted September 18, 2019 You need to create a module for this it is really a different thing I think. first learn how to develop a prestashop module than try exploring geolocation class you ll get some idea Link to comment Share on other sites More sharing options...
ADNREV Posted September 18, 2019 Author Share Posted September 18, 2019 1 minute ago, vividusdesigns said: You need to create a module for this it is really a different thing I think. first learn how to develop a prestashop module than try exploring geolocation class you ll get some idea @vividusdesigns thanks for help , , is there any zipped module to start ? Link to comment Share on other sites More sharing options...
vividusdesigns Posted September 18, 2019 Share Posted September 18, 2019 yes there is you can generate a basic module here https://validator.prestashop.com/ Link to comment Share on other sites More sharing options...
ADNREV Posted September 18, 2019 Author Share Posted September 18, 2019 1 minute ago, vividusdesigns said: yes there is you can generate a basic module here https://validator.prestashop.com/ @vividusdesigns thanks again 💪 Link to comment Share on other sites More sharing options...
vividusdesigns Posted September 18, 2019 Share Posted September 18, 2019 You are welcome ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now