regoch Posted November 7, 2011 Share Posted November 7, 2011 I got this script for changing language in my page. Now I wonder is there any way to find out from visitor IP from what country is he coming and automatic change language to his language, and if language is not in array to select english. jezik means language in croatian <?php function pronadiJezik() { $jezici = array('hr'=>'Hrvatski', 'en'=>'Engleski', 'de'=>'Njemački', 'it'=>'Talijanski', 'fr'=>'Francuski', 'cz'=>'Češki', 'pl'=>'Poljski'); if(isset($_SERVER["REDIRECT_URL"]) && $_SERVER["REDIRECT_URL"] != "/") { $url = $_SERVER["REDIRECT_URL"]; } else if(isset($_SERVER["REDIRECT_URI"]) && $_SERVER["REDIRECT_URI"] != "/") { $url = $_SERVER["REQUEST_URI"]; } else { $url = ""; } $jeziciA = array_keys($jezici); $url_parts = explode("/", $url); if(is_array($url_parts)) { foreach($url_parts as $n=>$v) { if(trim($v)!="") { if(in_array($v, $jeziciA)) { $jezik = $v; } } // end if $v!="" } // end foreach } // end if is_array return $jezik; } //---------------------------------------------------------- session_start(); $set_period = (60*60*24); if($_GET['lang']) { $_SESSION['jezik'] = $_GET['lang']; setcookie("jezik", $_GET['lang'], time()+ $set_period); } else { $_SESSION['jezik'] = pronadiJezik(); setcookie("jezik", $_SESSION['lang'], time()+ $set_period); } if(!$_SESSION['jezik'] or $_SESSION['jezik'] == "") { $_SESSION['jezik'] = "hr"; setcookie("jezik", "hr", time() + $set_period); } /////////////////////////////////////////////////////////////////////////HR if($_SESSION['jezik'] == "hr") { include "include/jezici/hr.php"; } /////////////////////////////////////////////////////////////////////////EN elseif($_SESSION['jezik'] == "en") { include "include/jezici/en.php"; } /////////////////////////////////////////////////////////////////////////DE elseif($_SESSION['jezik'] == "de") { include "include/jezici/de.php"; } /////////////////////////////////////////////////////////////////////////IT elseif($_SESSION['jezik'] == "it") { include "include/jezici/it.php"; } /////////////////////////////////////////////////////////////////////////FR elseif($_SESSION['jezik'] == "fr") { include "include/jezici/fr.php"; } /////////////////////////////////////////////////////////////////////////CZ elseif($_SESSION['jezik'] == "cz") { include "include/jezici/cz.php"; } /////////////////////////////////////////////////////////////////////////CZ elseif($_SESSION['jezik'] == "pl") { include "include/jezici/pl.php"; } ?> Link to comment https://forums.phpfreaks.com/topic/250649-how-to-detect-visitors-country/ Share on other sites More sharing options...
xyph Posted November 7, 2011 Share Posted November 7, 2011 There's TONS on the internet about this, and it can be a complex procedure. http://www.google.com/search?q=geolocation+via+ip Link to comment https://forums.phpfreaks.com/topic/250649-how-to-detect-visitors-country/#findComment-1286041 Share on other sites More sharing options...
The Little Guy Posted November 7, 2011 Share Posted November 7, 2011 GeoIP database: http://www.maxmind.com/app/geolitecity The API: http://www.maxmind.com/app/php This is a free php solution to getting a users Location based on their IP address. Link to comment https://forums.phpfreaks.com/topic/250649-how-to-detect-visitors-country/#findComment-1286045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.