<?php
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
geoip_close($gi);
switch($country_code) {
case "US": header("Location: http://US-URL"); break;
default: header("Location: http://RestOfTheWorld-URL");
}
?>
Are the geoip.dat and geoip.inc files both inside the same folder as the page?
Could you paste the entire code you have here?![]()
<?php
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
geoip_close($gi);
switch($country_code) {
case "US": header("Location: http://yahoo.com"); break;
default: header("Location: http://google.com");
}
?>
its the same as that person provided
Code:<?php include("geoip.inc"); $ip=$_SERVER['REMOTE_ADDR']; $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, "$ip"); geoip_close($gi); switch($country_code) { case "US": header("Location: http://yahoo.com"); break; default: header("Location: http://google.com"); } ?>
and i have geoio.inc and GeoIP.dat in the same directory as this index.html file
The code works great, just retested on one of my servers OP.
1. Delete the 2 files geoip.inc and GeoIP.dat you have now (maybe tainted?)
2. Make sure you get the geoip.inc from here:
http://geolite.maxmind.com/download/geoip/api/php/geoip.inc
3. get geoip.dat.gz (that you'll decompress so you'll end up with GeoIP.dat) from here:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
Retry and it'll work for sure.
HTH!![]()
Are you using this on an html page? You shouldn't be able to see any source code when you load the page in your browser from your web server. Your page must have a .php file extension and you should be inserting that code before the opening <html> tag. You must test this on a web server - just opening the page in your browser from your local hard drive won't parse the php code.
If you want to parse .html files for php includes, you can set that up in your .htaccess file (google "parse php in html htaccess").