geotarget by country, is this a working script ? (free downloadable scripts)

Discussion in 'HTML & Website Design' started by popnyc, May 29, 2008.

  1. #1
    www.ip2nation.com (all the scripts are free to download)
    has a sample country based redirection on their site, is this a working script for geotargeting by country that I can use? Or is it only a partial script? Do I need a MySQL database, or can I simply insert this into my html file?

    I'm looking for help on how to fill out this script and instructions on where to insert it into my html code, of how to find:confused: a MySQL database. If anyone could, please let me know, I can post a job listing under DP services buy/sell.

    <?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;
    }

    ?>
     
    popnyc, May 29, 2008 IP