1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[METHOD] Blackhat Codebreaker GeoIP modification

Discussion in 'CPA' started by Gandalf's Mate, Dec 1, 2009.

  1. Gandalf's Mate

    Gandalf's Mate Registered Member

    Joined:
    Mar 6, 2009
    Messages:
    51
    Likes Received:
    39
    Location:
    Under the sun
    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.
     
    • Thanks Thanks x 22
  2. oyeah22

    oyeah22 Power Member

    Joined:
    Nov 9, 2009
    Messages:
    633
    Likes Received:
    244
    Location:
    i dont remember
    nice! thanks :)
     
  3. Gandalf's Mate

    Gandalf's Mate Registered Member

    Joined:
    Mar 6, 2009
    Messages:
    51
    Likes Received:
    39
    Location:
    Under the sun
    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.
     
  4. dishnetboi

    dishnetboi Power Member

    Joined:
    Aug 23, 2009
    Messages:
    507
    Likes Received:
    97
    Occupation:
    I am my boss
    Location:
    US
    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
     
  5. Benditer

    Benditer Junior Member

    Joined:
    Aug 13, 2009
    Messages:
    125
    Likes Received:
    37
    Occupation:
    Many
    Location:
    Future
    Very useful indeed. It will certainly help in maximizing my returns.
     
  6. billrolls

    billrolls BANNED BANNED

    Joined:
    Jan 3, 2009
    Messages:
    184
    Likes Received:
    90
    This thread is going to be very useful for all of us.
    thanks OP...
     
  7. rudyvise

    rudyvise Jr. VIP Jr. VIP

    Joined:
    Jul 6, 2008
    Messages:
    358
    Likes Received:
    169
    Occupation:
    Corporate Copywriter
    Location:
    England
    outstanding. Give Op rep.
     
  8. Team Zissou

    Team Zissou Registered Member

    Joined:
    Apr 28, 2009
    Messages:
    98
    Likes Received:
    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
     
  9. Deusdies

    Deusdies Regular Member

    Joined:
    May 22, 2009
    Messages:
    261
    Likes Received:
    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 :)
     
  10. kimkils

    kimkils Power Member

    Joined:
    Jan 10, 2009
    Messages:
    663
    Likes Received:
    225
    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.
     
  11. Gandalf's Mate

    Gandalf's Mate Registered Member

    Joined:
    Mar 6, 2009
    Messages:
    51
    Likes Received:
    39
    Location:
    Under the sun
    Yep, that's it.
     
  12. dietbird

    dietbird Junior Member

    Joined:
    Nov 3, 2009
    Messages:
    126
    Likes Received:
    64
    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.
     
  13. backtobasics

    backtobasics Jr. VIP Jr. VIP

    Joined:
    Nov 10, 2009
    Messages:
    118
    Likes Received:
    45
    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
     
  14. Migladon

    Migladon Regular Member

    Joined:
    May 16, 2009
    Messages:
    229
    Likes Received:
    135
    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
     
  15. spenzo

    spenzo Senior Member

    Joined:
    Oct 20, 2009
    Messages:
    967
    Likes Received:
    553
    awesome share man..now everyone can use BHCB
     
  16. Gandalf's Mate

    Gandalf's Mate Registered Member

    Joined:
    Mar 6, 2009
    Messages:
    51
    Likes Received:
    39
    Location:
    Under the sun

    You'll have copied the code incorrectly. You've missed something on line 16 (or maybe 15.)
     
  17. kimkils

    kimkils Power Member

    Joined:
    Jan 10, 2009
    Messages:
    663
    Likes Received:
    225
    Using free hosting by any chance ?? :)

    000webhost gave me the same issue
     
  18. Gandalf's Mate

    Gandalf's Mate Registered Member

    Joined:
    Mar 6, 2009
    Messages:
    51
    Likes Received:
    39
    Location:
    Under the sun

    Ah, interesting. It pays to have your own server. ;)
     
  19. rey2k5

    rey2k5 Junior Member

    Joined:
    Nov 16, 2009
    Messages:
    130
    Likes Received:
    27
    Just bought BHCB myself and this is the only essential thing that is missing from the script! Thanks!
     
  20. TraucoX

    TraucoX Registered Member

    Joined:
    Oct 1, 2009
    Messages:
    60
    Likes Received:
    57
    Error establishing a database connection...

    =(
    No way...
    Also i test my db connection with other scripts and it´s work.