Get exclusive CAP network offers from top brands

View CAP Offers

anyone have a geotargeting

[bsa_pro_ad_space id=2]
  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #597430
    Anonymous
    Inactive

    script in place? can you share any insights or recommendations?

    #709163
    Anonymous
    Inactive

    I was going to ask this as well. If anyone has….do share please. Thanks

    #709169
    Anonymous
    Inactive

    yes

    But it goes through database and is in php…

    /// This is what you have to change, the location where it must be redirected
    $location=”http://www.whateverdomain.com”;

    //This is the US country code, you can change it if you want to test it for another country
    $code=”US”;

    define(‘IP2LOCATION_DB_HOST’, ‘localhost’);
    define(‘IP2LOCATION_DB_USER’, ‘ip2location’);
    define(‘IP2LOCATION_DB_PASS’, ‘ip2123+’);
    define(‘IP2LOCATION_DB_NAME’, ‘ip2location’);
    define(‘IP2LOCATION_DB_TABLE’, ‘IPREGIONCITYISP’);

    redirect($location, $code);

    function redirect($location,$code){
    $info=Geo::getCurrentLocation();
    if($info==$code){
    header(“Location: $location”);
    }
    }

    function encode($s)
    {
    $s = str_replace(‘\’, ‘\\’, $s);
    return str_replace(“‘”, “\'”, $s);
    }

    function execSQL($sql)
    {

    global $DEFAULT_CONNECTION;

    $r = @mysql_query($sql, $DEFAULT_CONNECTION);
    if (!$r)
    {
    $err = mysql_error();
    print_r(debug_backtrace());
    die($err . ‘

    ‘. $sql); // salvam vre-ul log cu sql si arr
    }
    return $r;
    }

    class Query
    {
    var $sql = null;
    var $r = null;
    var $a = null;

    function Query($_sql = ”)
    {
    $this->sql = $_sql;
    }

    function execute() // for internal use
    {
    $this->r = execSQL($this->sql);
    return $this->r;
    }

    //function &fetch()
    function fetch()
    {
    if (!$this->r) $this->execute();
    $this->a = mysql_fetch_array($this->r, MYSQL_ASSOC);
    return $this->a;
    }

    function getCount()
    {
    if (!$this->r) $this->execute();
    return mysql_num_rows($this->r);
    }

    function getArray($count = 0, $offset = 0)
    {
    if ($count > 0)
    {
    $osql = $this->sql;
    $this->sql .= ” limit $offset, “. ($offset+$count);
    }

    $this->execute();
    $this->a = false;
    $res = array();
    $i = 0;
    while ($a = $this->fetch())
    {
    if ($i < $lim_low) { $i++; continue; }
    if ($count > 0) if ($i >= $lim_low + $count) break;
    $i++;
    $res[] = $a;
    }

    if (count > 0)
    {
    $this->sql = $osql;
    }

    return $res;
    }

    function getArrayByID($id_field = “ID”)
    {
    $this->execute();
    $this->a = false;
    $res = array();
    while ($a = $this->fetch()) $res[$a[$id_field]] = $a;
    return $res;
    }

    function getAssocArray($key, $value)
    {
    $this->execute();
    $this->a = false;
    $res = array();
    while ($a = $this->fetch()) $res[$a[$key]] = $a[$value];
    return $res;
    }

    function getColumn($column, $index=””)
    {
    $this->execute();
    $this->a = false;
    $res = array();
    while ($a = $this->fetch())
    if ($index)
    $res[$a[$index]] = $a[$column];
    else
    $res[] = $a[$column];
    return $res;
    }

    function getScalar($column)
    {
    $this->execute();
    $this->a = $this->fetch();
    return $this->a[$column];
    }
    }

    class Table
    {
    var $table_name;
    var $keys;
    var $fields;
    var $auto_increment;

    function read($key_values) // assoc_array
    {
    if (count($this->keys) > 0); else die(‘No keys defined.’);

    $where = ”;
    foreach ($this->keys as $k=>$v) $where .= ” and `$v`='”.encode($key_values[$v]).”‘”;
    $where = substr($where, 4);

    $sql = “select * from `$this->table_name` where $where limit 1”;
    $r = new Query($sql);
    return $r->fetch();
    }

    function insert($values) // assoc_array
    {
    if ($this->auto_increment)
    unset($values[$this->keys[0]]);

    foreach($this->fields as $field_name => $field)
    {
    if (isset($values[$field_name]))
    {
    $a .= ‘,`’ . $field_name . ‘`’;
    $b .= ‘,” . encode($values[$field_name]) . ”’;
    }
    }

    $a = substr($a,1);
    $b = substr($b,1);

    if (execSQL(“insert into `{$this->table_name}`($a) values($b)”))
    {
    if ($this->auto_increment)
    return mysql_insert_id($GLOBALS);
    else
    return true;
    }
    else
    {
    return false;
    }
    }

    function update($key_values, $values) // assoc_array
    {
    if (count($this->keys) > 0); else die(‘No keys defined.’);

    foreach ($this->keys as $k=>$v) unset($values[$v]);

    $where = ”;
    foreach ($this->keys as $k=>$v) $where .= ” and `$v`='”.encode($key_values[$v]).”‘”;
    $where = substr($where, 4);

    foreach($this->fields as $field_name => $field)
    {
    if (isset($values[$field_name]))
    {
    $a .= ‘, `’ . $field_name . ‘`’;
    $a .= ‘=” . encode($values[$field_name]) . ”’;
    }
    }

    $a = substr($a,1);
    $b = substr($b,1);

    return execSQL(“update `{$this->table_name}` set $a where $where”);
    }

    function replace($key_values, $values) // assoc_array
    {
    if (count($this->keys) > 0); else die(‘No keys defined.’);

    foreach ($this->keys as $k=>$v) $values[$v] = $key_values[$v];

    foreach($this->fields as $field_name => $field)
    {
    if (isset($values[$field_name]))
    {
    $a .= ‘,`’ . $field_name . ‘`’;
    $b .= ‘,” . encode($values[$field_name]) . ”’;
    }
    }

    $a = substr($a,1);
    $b = substr($b,1);

    return execSQL(“replace into `{$this->table_name}`($a) values($b)”);
    }

    function delete($key_values) // assoc_array
    {
    if (count($this->keys) > 0); else die(‘No keys defined.’);

    $where = ”;
    foreach ($this->keys as $k=>$v) $where .= ” and `$v`='”.encode($key_values[$v]).”‘”;
    $where = substr($where, 4);

    return execSQL(“delete from `{$this->table_name}` where $where”);
    }
    }

    class Geo
    {
    function getCurrentLocation(){
    $ip = IP::getIP();
    $conn = mysql_connect(IP2LOCATION_DB_HOST, IP2LOCATION_DB_USER, IP2LOCATION_DB_PASS, true);
    mysql_select_db(IP2LOCATION_DB_NAME, $conn);
    $q = mysql_query(‘select * from ‘.IP2LOCATION_DB_TABLE.’ where ipFROM<='.$ip.' order by ipFROM desc limit 1', $conn);
    $a = mysql_fetch_array($q);
    if ($a && $a >= $ip)
    {
    $a = $a;
    $a = $a;
    $a = $a;
    $a = $ip;
    return $a;
    }
    else return false;
    }
    }

    class IP
    {
    function isValid($ip_addr)
    {
    $rr = array();
    if (!ereg(‘^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$’, $ip_addr, $rr)) return false;

    return true
    && ($rr[1] >= 0) && ($rr[1] <= 255)
    && ($rr[2] >= 0) && ($rr[2] <= 255)
    && ($rr[3] >= 0) && ($rr[3] <= 255)
    && ($rr[4] >= 0) && ($rr[4] <= 255);
    }

    function dotToLongIP ($IPaddr)
    {
    if ($IPaddr == “”)
    {
    return 0;
    }
    else
    {
    $ips = split (“.”, “$IPaddr”);
    return ($ips[3] + $ips[2] * 256 + $ips[1] * 65536 + $ips[0] * 16777216);
    }
    }

    function longIPToDot($ip, $zero_padding = false)
    {
    $w = ( $ip / 16777216 ) % 256;
    $x = ( $ip / 65536 ) % 256;
    $y = ( $ip / 256 ) % 256;
    $z = ( $ip ) % 256;
    if ($ip>2147483648)
    {
    $ipt=$ip-2147483648;
    $z=$ipt%256;
    }

    if ($zero_padding)
    return sprintf(“%03d.%03d.%03d.%03d”, $w,$x,$y,$z);
    else
    return “$w.$x.$y.$z”;
    }

    function getDotIP()
    {
    if (getenv(“HTTP_CLIENT_IP”) && strcasecmp(getenv(“HTTP_CLIENT_IP”), “unknown”))
    $ip = getenv(“HTTP_CLIENT_IP”);
    else if (getenv(“HTTP_X_FORWARDED_FOR”) && strcasecmp(getenv(“HTTP_X_FORWARDED_FOR”), “unknown”))
    $ip = getenv(“HTTP_X_FORWARDED_FOR”);
    else if (getenv(“REMOTE_ADDR”) && strcasecmp(getenv(“REMOTE_ADDR”), “unknown”))
    $ip = getenv(“REMOTE_ADDR”);
    else if (isset($_SERVER) && $_SERVER && strcasecmp($_SERVER, “unknown”))
    $ip = $_SERVER;
    else
    $ip = “”;
    return($ip);
    }

    function getIP()
    {
    return IP::dotToLongIP( IP::getDotIP() );
    }
    }

    ?>

    #709171
    Anonymous
    Inactive

    Thank you, Krystall, looks like I’ll have a lot of homework here :)

    #709188
    Anonymous
    Inactive

    No problem

    We did it as a

    include(“redirect.php”);
    ?>

    I have a list of US ips in myphpadmin database for this, but it is not the most current. I think it is about 6 months old now. Which is about 134000 ips :)

    #709198
    Anonymous
    Inactive

    very nice :) Thanks for posting it, I had it on my list of things to look for

    #709199
    Anonymous
    Inactive

    thanks for the script Kristal :-)

    #709203
    Anonymous
    Inactive

    You can get the database here for ips

    xxhttp://www.ip2location.com

    #709210
    Anonymous
    Inactive

    [HTML]Any thoughts on this idea?[/HTML]

    yeah tell them to VOTE against Republicans :)

    #709215
    Anonymous
    Inactive
    krystall2 wrote:
    yeah tell them to VOTE against Republicans :)

    Good idea. I might do that ;)

Viewing 10 posts - 1 through 10 (of 10 total)