I was using this script before then I switched my hosting and now it doesn´t work anymore. I´m a php noob so any help would be really appreciated.
<?php
$IP = $_SERVER["REMOTE_ADDR"];
include("geo/geoip.inc");
$gi = geoip_open("geo/GeoIP.dat", GEOIP_MEMORY_CACHE);
$CountryCode = geoip_country_code_by_addr($gi, $IP);
geoip_close($gi);
// ****DO NOT TOUCH ABOVE THIS LINE.******
if ($CountryCode=="US")
{
header('Location: http://date.com');
}
else if($CountryCode=="DK")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="ES")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="NO")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="SE")
{
header('Location: http://bsitm3.com');
}
else {
//Change this to reflect your international offers for country codes not listed above
header('Location: http://date.com');
}
?>
This requires that you download this script : http://www.mediafire.com/?r1913jmjcezwaot
and put the Geo file on your server.
It was working fine but then I switched servers and now I get this error:
Cannot redeclare geoip_country_code_by_name() in /home/UN/public_html/xxx.org/Geo/geo/geoip.inc on line 452
That would assume that the geoip_country_code_by_name function has already been declared before.
Have you spoken to your new Hosting company to see if they already have it installed on your server?
no, I haven´t I am going to ask beyond hosting and I´ll see if they can help with this.
Hey Andy,
Beyond hosting pretty much said what you did.
"Geoip is already enabled on the Server so in essence you are trying to call the script up a second time."
So how do I fix it? Do I just remove :
include("geo/geoip.inc");
?
just tried it and it didn´t work
Did it give you the same error?
As Andy said, your host likely has mod_geoip installed on your server already.
Do this: http://razvantudorica.wordpress.com/..._code_by_name/
Running the check that @kyleiwin recommends should do the job as long as it truly is the same function with the same parameters.
I use the MaxMind system also and installed it on my server myself.
My script looks like this:
[PHP]<?php
$keyword = $_GET['keyword'];
$subid2 = $_GET['subid2'];
$geo = geoip_record_by_name( $_SERVER['REMOTE_ADDR'] );
$countrycode = $geo['country_code'];
switch($countrycode) {
case 'US':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=XXXX&keyword=7S-USJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
case 'CA':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=XXXX&keyword=7S-CAJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
case 'GB':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=XXXX&keyword=7S-GBJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
case 'IE':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=1641&keyword=7S-IEJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
case 'AU':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=XXXX&keyword=7S-AUJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
case 'NZ':
$redirect[1] = 'http://andyscraven.com/demontracking/index.php/go?trackid=XXXX&keyword=7S-NZJC-'.$keyword;
$number = mt_rand(1,1);
header("Location:$redirect[$number]");
exit;
default:
$message = 'Traffic from: '.$countrycode.' : '.$keyword;
$timestamp = date('d/m/Y H:i:s');
$log_file = 'logs/7S-JustSearch_script.log';
error_log('['.$timestamp.'] INFO: '.$message.PHP_EOL, 3, $log_file);
header("location:http://www.justcloud.com");
exit;
}
?> [/PHP]
I have the rand(); in there just in case I want to rotate offers from here! You could remove that.
You will also notice that I store a log file for any non-qualifying traffic (default) so I know how much I am getting. I then send them to the base URL of my offer without my Aff ID, that way if you are using Facebook the reviewer can see the offer and there is less chance you will get disapproved!
I also append some useful info on to the front of the keyword passed from the traffic source to my tracker, like the Country Code etc.
As you are using Maxnind try this and see if it works. If they have pre-installed it you should not have to load the .DAT file either.
Run phpinfo (upload a php file with just "phpinfo()" inside of it then load it in your browser) and check geoip is listed amongst the modules. Then you need to change your script - some stuff needs to be removed and the country code call is incorrect. Should be record_by_name not country_code_by_addr.
[PHP]
<?php
$CountryCode = geoip_record_by_name( $_SERVER["REMOTE_ADDR"] );
// ****DO NOT TOUCH ABOVE THIS LINE.******
if ($CountryCode=="US")
{
header('Location: http://date.com');
}
else if($CountryCode=="DK")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="ES")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="NO")
{
header('Location: http://bsitm3.com');
}
else if($CountryCode=="SE")
{
header('Location: http://bsitm3.com');
}
else {
//Change this to reflect your international offers for country codes not listed above
header('Location: http://date.com');
}
?>
[/PHP]
Hey Guys,
Thanks for your posts.
Hey I tried both of your scripts and they don´t seem to work for me.
For Zeno´s I get this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/UN/public_html/xxxxx.org/Geo/index.php:1) in /home/UN/public_html/xxxxx.org/Geo/index.php on line 29
and for Andy´s I get this:
Warning: error_log(logs/7S-JustSearch_script.log) [function.error-log]: failed to open stream: No such file or directory in /home/UN/public_html/XXXX.org/Geo/index1.php on line 45
Warning: Cannot modify header information - headers already sent by (output started at /home/UN/public_html/XXXX.org/Geo/index1.php:1) in /home/UN/public_html/XXXX.org/Geo/index1.php on line 47
I´m running on liteSpeed. Does that change anything?
I tried Zeno´s script which makes sense to me but still doesn´t work.
I´m trying to hire somebody on Fiverr to help me out with this.
@wramirez617: Just delete the Log File stuff from the Default section. It seems you can't write the file.
I´m about to throw this computer out the window.

I haven´t installed maximind on my server. I think that is way too complicated for me right now.
lol
If you decide I have a good post that can help!
Not quite sure why you're getting that header error - seems almost like you are trying to do a header redirect but have already loaded page content so are not allowed. Check there are no white spaces before or after the ?> tags, i.e. you have a clean script.
You will need the MaxMind databases installed, no way around this. Just ask support to install the free MaxMind databases for you and ask them to check they are working properly.
Don't hire someone on Fiverr!? You are paying for premium hosting, use the support you are paying for!
@zeno is right, get them to do it!
http://ctrtard.com/code/blazing-geo-...n-your-server/
@andyscraven : you're getting expert !
^^^ haha... yes he does!
@andyscraven : you're everywhere!
@wramirez617 : just contact BH and they will install the db's for ya, that's what i did... (maxmind country +city db's)
Got a message from Tyler himself last night and he said that I already had the Free Maxmind Dbs on my server.
If using zeno's script... you must have some kind of whitespace before your opening "<?php" tag.. double check that there isn't a leading empty space or two before it in your file
if you're still having a problem, hit me up on skype tical525
i'm about to head out to grab something to eat but i'll help you once i get back (prob about 30-45 min)
Just added you tical
Which VPS package you've got?
PM me if you need help
Hey Guys, You are awesome.
Tical got on Skype with me and helped me out. So I got Zeno´s script to work. Or so I thought..... Until I actually make modifications to the links.
Now I can only get that last else clause to work. So its not accessing the the DB correctly.
@wramirez617: Insert the code again on here and wrap it in PHP codes so we can view it properly!
@andy : as long you are root, no need to su
@hs2010: I was logged in as an admin but not in root so rather than log out I just used su!
yes you're right
Hey Zeno that seemed to have worked. I got this back.
array(11) { ["continent_code"]=> string(2) "EU" ["country_code"]=> string(2) "ES" ["country_code3"]=> string(3) "ESP" ["country_name"]=> string(5) "Spain" ["region"]=> string(2) "29" ["city"]=> string(6) "Madrid" ["postal_code"]=> string(0) "" ["latitude"]=> float(40.4085998535) ["longitude"]=> float(-3.69219994545) ["dma_code"]=> int(0) ["area_code"]=> int(0) }
Try this:
<?php
$geodata= geoip_record_by_name( $_SERVER['REMOTE_ADDR'] );
switch($geodata["country_code"]) {
case "US":
header("Location: http://whatever.com");
break;
case "GB":
header("Location: http://whatever.com");
break;
case "SE":
header("Location: http://whatever.com");
break;
default:
header("Location: http://whatever.com");
}
?>
obviously edit that to have the country codes you want to use
Well the GEO stuff is working so it must be a code issue! If you post it on here inside PHP tags we can all take a look for you!
@zeno: Now why didn't I think of that? !!! :-)
Jason´s script works perfectly for me. Thanks J you´re a boss!
I thanked everyone for their input. I´m glad that shit´s over.
Yeah it is good to know you have that working but also it is introducing you to PHP, think about it, you can now put Geo stuff in to your Landers. Do you live in <Country Code>? :-)