• Hello all,

    I am currently using the Language Switcher plugin to provide 2 language versions of my blog, one is https://www.nektulos.de/lang/en/ the other is https://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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sylaan

    (@sylaan)

    Anyone ? ??

    Thread Starter sylaan

    (@sylaan)

    I can’t believe nobody tried to do this before …

    I was looking for the same thing. I have found this: https://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: https://www.thelocal.se/&#8217;);
    exit;
    case ‘us’:
    // And let the folks from american go to CNN
    header(‘Location: https://www.cnn.com/&#8217;);
    exit;
    default:
    // The rest can go to BBC
    header(‘Location: https://www.bbc.co.uk/&#8217;);
    exit;
    }

    ?>

    Hey sylaan,

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Redirect based on geo-location’ is closed to new replies.