Forums

Redirect based on geo-location (5 posts)

  1. sylaan
    Member
    Posted 3 years ago #

    Hello all,

    I am currently using the Language Switcher plugin to provide 2 language versions of my blog, one is http://www.nektulos.de/lang/en/ the other is http://www.nektulos.de/lang/ro/.

    The plugin has some automated redirection mechanisms based on previous user choices and browser language but I need to do the redirect based on IP address. If people come from Romania, I need to provide the /lang/ro/ version, if not, then the /lang/en/ one.

    I know which function of that plugin does the redirection but I don't really know how to implement it based on IP address (i.e. country). Any idea how I could go about it ?

    Any info is appreciated.

    Best regards,
    Stefan

  2. sylaan
    Member
    Posted 3 years ago #

    Anyone ? ;-)

  3. sylaan
    Member
    Posted 3 years ago #

    I can't believe nobody tried to do this before ...

  4. DontRetail
    Member
    Posted 3 years ago #

    I was looking for the same thing. I have found this: http://www.ip2nation.com/ip2nation/Sample_Scripts

    <?php

    $server = ''; // MySQL hostname
    $username = ''; // MySQL username
    $password = ''; // MySQL password
    $dbname = ''; // MySQL db name

    $db = mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $sql = 'SELECT
    country
    FROM
    ip2nation
    WHERE
    ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
    ORDER BY
    ip DESC
    LIMIT 0,1';

    list($country) = mysql_fetch_row(mysql_query($sql));

    switch ($country) {
    case 'se':
    // Get the swedish to a swedish newssite
    header('Location: http://www.thelocal.se/');
    exit;
    case 'us':
    // And let the folks from american go to CNN
    header('Location: http://www.cnn.com/');
    exit;
    default:
    // The rest can go to BBC
    header('Location: http://www.bbc.co.uk/');
    exit;
    }

    ?>

  5. leihla
    Member
    Posted 2 years ago #

    Hey sylaan,

    I also want to target users by their location. I wonder if you were able do it?
    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic