SIMPLE REDIRECTION pls HELP

  • Ads

SIMPLE REDIRECTION pls HELP

Postby mikcheck » Fri Apr 02, 2010 8:54 am

hi, is there a simple way to redirect people using your api by city with php?!

eg:
if city = naples
go to > rootdir/naples

if city = milan
go to > rootdir/milan
mikcheck
 
Posts: 3
Joined: Fri Apr 02, 2010 8:51 am

Re: SIMPLE REDIRECTION pls HELP

Postby marchost » Fri Apr 02, 2010 9:50 am

yes, you can do something like

if ($city = 'milan') {
header('Location: http://www.example.com/milan');
} elseif ($city = 'naples') {
header('Location: http://www.example.com/naples');
} else {
//do something
}
marchost
Site Admin
 
Posts: 374
Joined: Wed Apr 08, 2009 9:55 pm

Re: SIMPLE REDIRECTION pls HELP

Postby mikcheck » Fri Apr 02, 2010 11:02 am

tnx for code, now how can I set $city using apis?
i think will be useful for a lot of people if someone can post a complete working source

marchost wrote :
> yes, you can do something like
>
> if ($city = 'milan') {
> header('Location: http://www.example.com/milan');
> } elseif ($city = 'naples') {
> header('Location: http://www.example.com/naples');
> } else {
> //do something
> }
mikcheck
 
Posts: 3
Joined: Fri Apr 02, 2010 8:51 am

Re: SIMPLE REDIRECTION pls HELP

Postby marchost » Mon Apr 05, 2010 8:06 pm

Hi, if you read carefully the API page, you should find your answer :

http://ipinfodb.com/ip_location_api.php

Thanks
Marc
marchost
Site Admin
 
Posts: 374
Joined: Wed Apr 08, 2009 9:55 pm

Re: SIMPLE REDIRECTION pls HELP

Postby mikcheck » Tue Apr 06, 2010 5:53 pm

tnx, here's working code, topic solved :D

//******************************************//

<?php
function locateIp($ip){
$d = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");

//Use backup server if cannot make a connection
if (!$d){
$backup = file_get_contents("http://backup.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");
$answer = new SimpleXMLElement($backup);
if (!$backup) return false; // Failed to open connection
}else{
$answer = new SimpleXMLElement($d);
}

$ip = $answer->Ip;
$country_code = $answer->CountryCode;
$country_name = $answer->CountryName;
$region_name = $answer->RegionName;
$city = $answer->City;
$zippostalcode = $answer->ZipPostalCode;
$latitude = $answer->Latitude;
$longitude = $answer->Longitude;

//Return the data as an array
return array('ip' => $ip, 'country_code' => $country_code, 'country_name' => $country_name, 'region_name' => $region_name, 'city' => $city, 'zippostalcode' => $zippostalcode, 'latitude' => $latitude, 'longitude' => $longitude);
}

//Usage example



//REDIR USER BY CITY

//RETRIVE USER IP

$ip = $_SERVER['REMOTE_ADDR'];

$ip_data = locateIp($ip);

//echo "IP : " . $ip_data['ip'] . "\n";
//echo "Country code : " . $ip_data['country_code'] . "\n";
//echo "Country name : " . $ip_data['country_name'] . "\n";
//echo "Region name : " . $ip_data['region_name'] . "\n";
//echo "City : " . $ip_data['city'] . "\n";
//echo "Zip/postal code : " . $ip_data['zippostalcode'] . "\n";
//echo "Latitude : " . $ip_data['latitude'] . "\n";
//echo "Longitude : " . $ip_data['longitude'] . "\n";

//CHECK CITY NAME THEN REDIR

$city2redir = $ip_data['city'];

//echo "" . $city2redir . "\n";

if ($city2redir == "Milan") {
header('Location: ./milano/');
}
elseif ($city2redir == "Naples") {
header('Location: ./napoli/');
}
elseif ($city2redir == "Rome") {
header('Location: ./rome/');
}
else {
header('Location: ./no_city_in_db/');
}

//***************************//
mikcheck
 
Posts: 3
Joined: Fri Apr 02, 2010 8:51 am


Return to IP geolocation API related



Who is online

Users browsing this forum: No registered users and 1 guest