Forum Moderators: coopster

Message Too Old, No Replies

GeoIP redirect by city

         

m223

10:32 am on Jun 2, 2011 (gmt 0)

10+ Year Member



Hi,

Does anyone have any experience with maxmind geoip city?
im trying to redirect users to a different page based on the city they are coming from

I have tried...

<?php
require_once("geoipcity.inc");
$gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
$city = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
if($city == 'Sydney')
{
header("HTTP/1.1 301 Moved Permanently");
header('Location: http:/ example1.com');
}
else
{
header("HTTP/1.1 301 Moved Permanently");
header('Location: http:/ example2.com');
}
?>

i dont have a lot of experience with PHP but i can get this to work for redirecting based on country, but by city it doesnt work no matter what i try!
if someone could point me in the right direction to get this working i would be really greatfull,

rocknbil

5:38 pm on Jun 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use geoplugin, so have never used this service - but what happens when you do this?

$city = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
echo "The city is $city";
exit;

m223

11:14 pm on Jun 2, 2011 (gmt 0)

10+ Year Member



Thankyou so much! :)
I tried geoplugin and it is great, it does exactly what i want it to do

[edited by: coopster at 1:54 am (utc) on Jun 3, 2011]
[edit reason] code link not necessary, thanks [/edit]