GeoIP redirect by city

by vaz334
5 replies
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,
#city #geoip #redirect
  • Profile picture of the author XoC
    I made a script a while ago to do this exactly (people in Australia too!) but unfortunately I cannot find it now however I think I see what you're doing wrong..

    $geoArray = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);

    if($geoArray['city'] == 'Sydney')
    {
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: example1');
    }

    I just checked the help docs and the function geoip_record_by_addr() actually outputs an array.

    Hopefully that helps you!
    {{ DiscussionBoard.errors[4000768].message }}
  • Profile picture of the author ussher
    let the user choose.

    Google has got a "Great" feature where it decides that because i am IN japan that i MUST want all my content in Japanese. I hate it.

    Myspace too "Oh, we know where you are, so we know what you want."

    Let your users choose, then store that in a cookie and bring them back to what they chose next time.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[4000941].message }}
    • Profile picture of the author XoC
      Originally Posted by ussher View Post

      let the user choose.

      Google has got a "Great" feature where it decides that because i am IN japan that i MUST want all my content in Japanese. I hate it.

      Myspace too "Oh, we know where you are, so we know what you want."

      Let your users choose, then store that in a cookie and bring them back to what they chose next time.
      You're right, that can be an annoying feature if not easily modified or changed but I think his script is either most likely to be used for geo targeting CPA offers or because he's just redirecting within local cities there wouldn't be any language barriers..
      {{ DiscussionBoard.errors[4001061].message }}
  • Profile picture of the author ussher
    so the user is in Chicago on holiday but lives in Washington. comes back to check the page he always visits and becuase he is in Chicargo gets a completely different page than he expected.

    Careful with redirects, they can be immensely frustrating.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[4001259].message }}
  • Profile picture of the author ionisis
    That's because it becomes increasingly LESS accurate with the more you try to fine tune the location detection. The finer tuned the Data is, the more inaccurate it is. GeoIP information changes to quickly to be reliable at the City level. Try using State/Region/Subdivision level.
    {{ DiscussionBoard.errors[4057853].message }}

Trending Topics