setKey($apikey); $locations = $ipLite->getCity($ip); setCookieCustom($field, $locations[$field]); //print_r($locations); return $locations[$field]; } else { //echo 'set'; return $_COOKIE[$field]; } } function setCookieCustom($name, $val) { setcookie($name, $val, time() + 3600, '/'); } function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } $cName= geo(getRealIpAddr(),'countryCode'); switch ($cName) { case 'GR': header("Location: http://www.antennaeurope.gr/app/photocontest/home#photocontest"); break; case 'US': header("Location: http://www.antennasatellite.gr/app/photocontest/home#photocontest"); break; case 'AU': header("Location: http://www.antennapacific.gr/app/photocontest/home#photocontest"); break; default: header("Location: http://www.antennaeurope.gr/app/photocontest/home#photocontest"); } final class ip2location_lite{ protected $errors = array(); protected $service = 'api.ipinfodb.com'; protected $version = 'v3'; protected $apiKey = ''; public function __construct(){} public function __destruct(){} public function setKey($key){ if(!empty($key)) $this->apiKey = $key; } public function getError(){ return implode("\n", $this->errors); } public function getCountry($host){ return $this->getResult($host, 'ip-country'); } public function getCity($host){ return $this->getResult($host, 'ip-city'); } private function getResult($host, $name){ $ip = @gethostbyname($host); if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){ $xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml'); try{ $response = @new SimpleXMLElement($xml); foreach($response as $field=>$value){ $result[(string)$field] = (string)$value; } return $result; } catch(Exception $e){ $this->errors[] = $e->getMessage(); return; } } $this->errors[] = '"' . $host . '" is not a valid IP address or hostname.'; return; } } ?>