Gandalf's Mate
Registered Member
- Mar 6, 2009
- 51
- 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:
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:
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)
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.
6. Now rename your current links.txt file to something else.
7. Create a file called '\links.php' and paste the following into it:
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.
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
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;
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
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());
?>
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.
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.