[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.
 

Gandalf's Mate

Registered Member
Joined
Mar 6, 2009
Messages
51
Reaction score
40
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.
 

dishnetboi

Power Member
Joined
Aug 23, 2009
Messages
508
Reaction score
97
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
 

Benditer

Junior Member
Joined
Aug 13, 2009
Messages
125
Reaction score
37
Very useful indeed. It will certainly help in maximizing my returns.
 

billrolls

BANNED
Joined
Jan 3, 2009
Messages
184
Reaction score
91
This thread is going to be very useful for all of us.
thanks OP...
 

Team Zissou

Registered Member
Joined
Apr 28, 2009
Messages
98
Reaction score
62
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
 

Deusdies

Regular Member
Joined
May 22, 2009
Messages
262
Reaction score
190
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 :)
 

kimkils

Power Member
Joined
Jan 10, 2009
Messages
669
Reaction score
231
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.
 

Gandalf's Mate

Registered Member
Joined
Mar 6, 2009
Messages
51
Reaction score
40
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
Yep, that's it.
 

dietbird

Junior Member
Joined
Nov 3, 2009
Messages
126
Reaction score
65
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.
 

backtobasics

Junior Member
Joined
Nov 10, 2009
Messages
147
Reaction score
57
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
 

Migladon

Regular Member
Joined
May 16, 2009
Messages
229
Reaction score
136
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
 

spenzo

Senior Member
Joined
Oct 20, 2009
Messages
967
Reaction score
557
awesome share man..now everyone can use BHCB
 

Gandalf's Mate

Registered Member
Joined
Mar 6, 2009
Messages
51
Reaction score
40
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 http://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.)
 

kimkils

Power Member
Joined
Jan 10, 2009
Messages
669
Reaction score
231
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
 

rey2k5

Junior Member
Joined
Nov 16, 2009
Messages
147
Reaction score
38
Just bought BHCB myself and this is the only essential thing that is missing from the script! Thanks!
 
Top