[METHOD] Blackhat Codebreaker GeoIP modification

Gandalf's Mate

Registered Member
Joined
Mar 6, 2009
Messages
51
Reaction score
40
I bought Blackhat Codebreaker (BHCB) about 24 hrs ago. It's a brilliant piece of coding, but it's missing an essential feature, the ability to target offers based on the visitors location. I believe this is being addressed in a future version, but until then...

Ok, above the standard BHCB requirements, your server must support the following:
Apache's mod_rewrite
.htaccess
MySQL

So, let's get started.

1. You will need to download the MaxMind GeoLite Country Database. You can get it here:
Code:
http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
2. Create a MySQL Database that will hold the GeoIP's, I called mine geoip. Then we'll create a table, called 'country'. Here's the SQL to create the table:

Code:
CREATE TABLE IF NOT EXISTS `country` (
  `begin_ip` varchar(15) NOT NULL,
  `end_ip` varchar(15) NOT NULL,
  `begin_ipn` int(11) NOT NULL,
  `end_ipn` int(11) NOT NULL,
  `country_code` varchar(2) NOT NULL,
  `country_name` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
3. Now we need to get the data into the table. Just use PHPMyAdmin and "Import" the CSV file you downloaded in Step 1.

Ok, that's the Database out the way, now for the web files. As you should know, BHCB uses a file called 'links.txt' to display the links you want when blocking your content. We need to dynamically create that file. To do this we'll use Apache's mod_rewrite with a .htaccess file.

4. Add the following lines to your .htaccess file. (If you don't have one, create one)

Code:
RewriteEngine on
RewriteRule ^links\.txt$ links.php
5. Create a file called "\geoip.php" This is going to contain some functions. Paste the following into it. Be sure to alter it to use your MySQL username/password and database name in the mysql_connect mysql_select_db lines near the end of the file.

Code:
<?php
function getALLfromIP($addr) {
        $query = "SELECT country_code, country_name FROM geoip.country WHERE end_ipn >= INET_ATON('$addr') ORDER BY end_ipn $
        $result = mysql_query($query);
        if((! $result) or mysql_numrows($result) < 1) {
                return false;
        }
        return mysql_fetch_array($result);
}
function getCCfromIP($addr) {
        $data = getALLfromIP($addr);
        if($data) return $data;
        return false;
}

mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("geoip") or die(mysql_error());
?>
6. Now rename your current links.txt file to something else.

7. Create a file called '\links.php' and paste the following into it:

Code:
<?php
include ("geoip.php");

$country_data = getCCfromIP($_SERVER['REMOTE_ADDR']);
switch ($country_data['country_code']) {

        case "US":
                echo "Google US Search Engine
http://www.google.com
Yahoo US
http://www.yahoo.com
";
                break;

        case "GB":
                echo "Google UK Search Engine
http://www.google.com.uk
Yahoo UK
http://www.yahoo.co.uk
";
                break;

        default:
                echo "Disney
http://www.disney.com
Gravy
http://www.gravy.com
";
                break;
}
?>

**** PUT YOUR CPA LINKS ABOVE THIS LINE. DO NOT ERASE IT. DO NOT ADD BLANK LINES ABOVE IT. BENEATH THIS LINE ADD YOUR DEFAULT FALLBACK LINK URL, WITHOUT ANCHOR TEXT.
http://www.fallbacklink.com
**** THIS MUST BE THE FINAL LINE. DO NOT ERASE IT. DO NOT ADD BLANK LINES ABOVE IT. DO NOT ADD ANY LINES BENEATH IT. THE FILE MUST END HERE.
That's it. Just add new 'case' with the country code for a different country.

You can test it by accessing the "links.txt" file on your site like so: http://www.domain.com/links.txt

Hope that helps someone.
 
I forgot to add, you can't hide the referrer with this method as the actual links.txt file is used in the DMR built into BHCB. So if you want to hide the referrer you will need to use your own DMR or 202 or whatever.
 
Thanks a ton! this can help alot when it comes to geotargeting offers so the stupid network doesn't do it automatically give you crappy EPCs
 
Very useful indeed. It will certainly help in maximizing my returns.
 
This thread is going to be very useful for all of us.
thanks OP...
 
Thanks. I have a few questions:

The new links.php file is the one where your links now go, correct? If so, what's the format for adding more links? I'm understanding it to start as:

echo "Link Name
http://Site.com
Link Name
http://Site.com
";

Am I right? :P
 
Unbelievable. I was just about to write a tutorial on my modification of BHCB for GeoIP targeting :) My method is different, but does the same thing :)
 
Ive done this a while ago, all i did was have a single "Click me" link in the links.txt that directs to a php file where the geo locating code is, much simpler to implement. Credits to OP for writing it up though.
 
You can also make the links in BHCB say something similar to this:

United States
United Kingdom
Canada
Australia

And have a corresponding offer for each country.
 
This is all very interesting. I know in the Dirty CPA course they offer a WP plugin that does this.

I know nothing about coding WP plugins. Anyone have any idea how difficult it would be to take the above and make it into one? Could be worth hiring a coder to do it.

Just wondering.

BtoB
 
Can you please help me out? Ive gotten everything setup but when i go to my website, the content blocker has no links on it. Also, when i go to www.mydomain.com/links.txt i get an error saying

Parse error: syntax error, unexpected T_STRING in /home/account/public_html/website/geoip.php on line 16

Please Help will be much appreciated

thx
 
Can you please help me out? Ive gotten everything setup but when i go to my website, the content blocker has no links on it. Also, when i go to www.mydomain.com/links.txt i get an error saying

Parse error: syntax error, unexpected T_STRING in /home/account/public_html/website/geoip.php on line 16

Please Help will be much appreciated

thx


You'll have copied the code incorrectly. You've missed something on line 16 (or maybe 15.)
 
Can you please help me out? Ive gotten everything setup but when i go to my website, the content blocker has no links on it. Also, when i go to www.mydomain.com/links.txt i get an error saying

Parse error: syntax error, unexpected T_STRING in /home/account/public_html/website/geoip.php on line 16

Please Help will be much appreciated

thx

Using free hosting by any chance ?? :)

000webhost gave me the same issue
 
Just bought BHCB myself and this is the only essential thing that is missing from the script! Thanks!
 
Back
Top