Home > Programming, Servers & Scripts >

GEO Redirect Script - Stopped working (40)


11-20-2012 10:22 AM #1 wramirez617 (Member)
GEO Redirect Script - Stopped working

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


11-20-2012 11:19 AM #2 andyscraven (Member)

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?


11-20-2012 11:27 AM #3 wramirez617 (Member)

no, I haven´t I am going to ask beyond hosting and I´ll see if they can help with this.


11-20-2012 12:40 PM #4 wramirez617 (Member)

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");

?


11-20-2012 12:46 PM #5 wramirez617 (Member)

just tried it and it didn´t work


11-20-2012 02:56 PM #6 andyscraven (Member)

Did it give you the same error?


11-20-2012 02:58 PM #7 kyleirwin (Member)

As Andy said, your host likely has mod_geoip installed on your server already.

Do this: http://razvantudorica.wordpress.com/..._code_by_name/


11-20-2012 03:13 PM #8 andyscraven (Member)

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.


11-20-2012 05:33 PM #9 zeno (Administrator)

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]


11-20-2012 07:04 PM #10 wramirez617 (Member)

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.


11-20-2012 07:09 PM #11 andyscraven (Member)

@wramirez617: Just delete the Log File stuff from the Default section. It seems you can't write the file.


11-20-2012 07:33 PM #12 wramirez617 (Member)

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.


11-20-2012 07:37 PM #13 andyscraven (Member)

lol

If you decide I have a good post that can help!


11-20-2012 07:53 PM #14 zeno (Administrator)

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!


11-20-2012 07:57 PM #15 andyscraven (Member)

@zeno is right, get them to do it!


11-20-2012 09:04 PM #16 wramirez617 (Member)

Quote Originally Posted by andyscraven View Post
lol

If you decide I have a good post that can help!

Where is this post?

I just requested that Beyond Hosting install the Dbs on my server.


11-20-2012 09:25 PM #17 andyscraven (Member)

http://ctrtard.com/code/blazing-geo-...n-your-server/


11-20-2012 11:54 PM #18 hd2010 (Member)

@andyscraven : you're getting expert !


11-21-2012 05:20 AM #19 Oded Abbou (Member)

^^^ 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)


11-21-2012 08:31 AM #20 wramirez617 (Member)

Got a message from Tyler himself last night and he said that I already had the Free Maxmind Dbs on my server.

Hi william, the free version is loaded on the hybrid server. If you need a custom version you must upgrade to VPS768 or better.

If you have further questions please feel free to ask.

So Why doesn´t the code work. This is nuts


11-21-2012 08:47 AM #21 tical (Member)

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


11-21-2012 08:49 AM #22 tical (Member)

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)


11-21-2012 09:44 AM #23 wramirez617 (Member)

Just added you tical


11-21-2012 09:51 AM #24 Oded Abbou (Member)

Which VPS package you've got?


11-21-2012 10:20 AM #25 hd2010 (Member)

PM me if you need help


11-21-2012 10:52 AM #26 andyscraven (Member)

Quote Originally Posted by hd2010 View Post
@andyscraven : you're getting expert !
lol! Gotta love the geeky side! Only took about an hour to install and test on my server! Once I realised I neeed to log in with Adim rights and become a Super User using the 'sudo su' command!


11-21-2012 06:05 PM #27 wramirez617 (Member)

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.


11-21-2012 06:32 PM #28 andyscraven (Member)

@wramirez617: Insert the code again on here and wrap it in PHP codes so we can view it properly!


11-21-2012 06:59 PM #29 hd2010 (Member)

@andy : as long you are root, no need to su


11-21-2012 07:01 PM #30 andyscraven (Member)

@hs2010: I was logged in as an admin but not in root so rather than log out I just used su!


11-21-2012 07:03 PM #31 hd2010 (Member)

yes you're right


11-21-2012 08:16 PM #32 zeno (Administrator)

Quote Originally Posted by wramirez617 View Post
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.
Use a test page that just dumps/echos all the geoip data to test it's working.

E.g.

[PHP]
<?php
$geodata= geoip_record_by_name( $_SERVER['REMOTE_ADDR'] );

var_dump($geodata);

?>
[/PHP]


11-22-2012 10:15 AM #33 wramirez617 (Member)

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) }


11-22-2012 11:00 AM #34 tical (Member)

Try this:

Code:
<?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");
	}
?>


11-22-2012 11:01 AM #35 tical (Member)

obviously edit that to have the country codes you want to use


11-22-2012 12:16 PM #36 andyscraven (Member)

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!


11-22-2012 07:51 PM #37 zeno (Administrator)

Quote Originally Posted by wramirez617 View Post
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) }
Yes so your geoip stuff is working fine, so any failures in the georedirect scripts working will be a coding error somewhere. Make sure you're opening the PHP files in something that has syntax checking to pick up on anything obvious.


11-22-2012 07:57 PM #38 andyscraven (Member)

@zeno: Now why didn't I think of that? !!! :-)


11-23-2012 07:58 AM #39 wramirez617 (Member)

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.


11-23-2012 08:19 AM #40 andyscraven (Member)

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>? :-)


Home > Programming, Servers & Scripts >